@almadar/agent 2.0.0 → 2.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.
Files changed (100) hide show
  1. package/dist/agent/event-budget.d.ts +28 -0
  2. package/dist/agent/experimental/hitl-v2.d.ts +161 -0
  3. package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
  4. package/dist/agent/index.d.ts +14 -0
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/interrupt-config.d.ts +51 -0
  7. package/dist/agent/session-manager.d.ts +204 -0
  8. package/dist/agent/skill-agent.d.ts +182 -0
  9. package/dist/agent/workflow-middleware.d.ts +63 -0
  10. package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
  11. package/dist/api-types.d.ts +595 -0
  12. package/dist/context/compaction.d.ts +191 -0
  13. package/dist/context-compaction.d.ts +55 -0
  14. package/dist/evals/online-sampling.d.ts +114 -0
  15. package/dist/evals/utils/compact-orbital.d.ts +100 -0
  16. package/dist/event-transformer/event-transformer.d.ts +120 -0
  17. package/dist/event-transformer/index.d.ts +7 -0
  18. package/dist/events.d.ts +85 -0
  19. package/dist/index.d.ts +59 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/memory/MemoryManager.d.ts +243 -0
  22. package/dist/memory/PreferenceLearner.d.ts +59 -0
  23. package/dist/memory/agentic-search.d.ts +116 -0
  24. package/dist/memory/index.d.ts +14 -0
  25. package/dist/memory/memory-orbital.d.ts +66 -0
  26. package/dist/memory/types.d.ts +143 -0
  27. package/dist/metrics.d.ts +77 -0
  28. package/dist/multi-user.d.ts +155 -0
  29. package/dist/observability/index.d.ts +14 -0
  30. package/dist/observability/langsmith-integration.d.ts +203 -0
  31. package/dist/observability.d.ts +196 -0
  32. package/dist/orbitals/archive/sanitize.d.ts +24 -0
  33. package/dist/orbitals/batch/batch-generator.d.ts +41 -0
  34. package/dist/orbitals/batch/concurrency.d.ts +54 -0
  35. package/dist/orbitals/batch/index.d.ts +14 -0
  36. package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
  37. package/dist/orbitals/batch/types.d.ts +103 -0
  38. package/dist/orbitals/cache/index.d.ts +11 -0
  39. package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
  40. package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
  41. package/dist/orbitals/cache/structural-templates.d.ts +33 -0
  42. package/dist/orbitals/combiner/index.d.ts +102 -0
  43. package/dist/orbitals/domain-language/index.d.ts +9 -0
  44. package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
  45. package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
  46. package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
  47. package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
  48. package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
  49. package/dist/orbitals/generation/index.d.ts +10 -0
  50. package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
  51. package/dist/orbitals/shared/constants.d.ts +65 -0
  52. package/dist/orbitals/shared/index.d.ts +11 -0
  53. package/dist/orbitals/shared/types.d.ts +187 -0
  54. package/dist/orbitals/shared/utils.d.ts +97 -0
  55. package/dist/orchestration/complexity-classifier.d.ts +38 -0
  56. package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
  57. package/dist/orchestration/index.d.ts +31 -0
  58. package/dist/orchestration/provider-router.d.ts +45 -0
  59. package/dist/persistence/firestore-checkpointer.d.ts +139 -0
  60. package/dist/persistence/firestore-session-store.d.ts +75 -0
  61. package/dist/persistence/firestore-store.d.ts +86 -0
  62. package/dist/persistence/index.d.ts +10 -0
  63. package/dist/persistence/memory-backend.d.ts +33 -0
  64. package/dist/persistence/types.d.ts +40 -0
  65. package/dist/security/audit-log.d.ts +44 -0
  66. package/dist/state-sync.d.ts +171 -0
  67. package/dist/subagents.d.ts +38 -0
  68. package/dist/tools/combine-schemas.d.ts +154 -0
  69. package/dist/tools/composition.d.ts +119 -0
  70. package/dist/tools/domain-orbital.d.ts +997 -0
  71. package/dist/tools/execute.d.ts +38 -0
  72. package/dist/tools/finish-task.d.ts +56 -0
  73. package/dist/tools/generate-schema.d.ts +53 -0
  74. package/dist/tools/github.d.ts +297 -0
  75. package/dist/tools/index.d.ts +1318 -0
  76. package/dist/tools/orbital-batch-subagent.d.ts +85 -0
  77. package/dist/tools/orbital-subagent.d.ts +454 -0
  78. package/dist/tools/orchestrated-fixing.d.ts +74 -0
  79. package/dist/tools/orchestrated-generation.d.ts +75 -0
  80. package/dist/tools/sandbox-executor.d.ts +31 -0
  81. package/dist/tools/schema-chunking.d.ts +117 -0
  82. package/dist/tools/trait-subagent.d.ts +179 -0
  83. package/dist/tools/validate-schema.d.ts +17 -0
  84. package/dist/types.d.ts +167 -0
  85. package/dist/utils/safety/capability-token.d.ts +50 -0
  86. package/dist/utils/safety/circuit-breaker.d.ts +71 -0
  87. package/dist/utils/safety/index.d.ts +19 -0
  88. package/dist/utils/safety/rate-limiter.d.ts +39 -0
  89. package/dist/utils/safety/threshold-auth.d.ts +70 -0
  90. package/dist/workspace/git-client.d.ts +51 -0
  91. package/dist/workspace/index.d.ts +38 -0
  92. package/dist/workspace/memory-files.d.ts +31 -0
  93. package/dist/workspace/sink-manager.d.ts +26 -0
  94. package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
  95. package/dist/workspace/sinks/git-sink.d.ts +47 -0
  96. package/dist/workspace/sinks/index.d.ts +9 -0
  97. package/dist/workspace/templates.d.ts +32 -0
  98. package/dist/workspace/types.d.ts +86 -0
  99. package/dist/workspace/workspace-manager.d.ts +57 -0
  100. package/package.json +7 -6
@@ -0,0 +1,31 @@
1
+ /**
2
+ * SandboxExecutor — V8 isolate-based sandboxed code execution.
3
+ *
4
+ * Uses `isolated-vm` to run untrusted code in a separate V8 context
5
+ * with configurable memory and time limits. Stronger isolation than
6
+ * Node.js `vm` module (separate heap, no shared references).
7
+ *
8
+ * This is an Almadar-specific addition to the IC-AGI security layer.
9
+ * It will be contributed to almadar-io/ic-agi as an optional module.
10
+ */
11
+ export interface SandboxOptions {
12
+ /** Execution timeout in milliseconds. Default: 5000 */
13
+ timeoutMs?: number;
14
+ /** Memory limit for the isolate in MB. Default: 32 */
15
+ memoryLimitMb?: number;
16
+ }
17
+ export interface SandboxResult {
18
+ success: boolean;
19
+ value?: unknown;
20
+ error?: string;
21
+ timedOut?: boolean;
22
+ }
23
+ /**
24
+ * Execute a JavaScript code string inside a V8 isolate.
25
+ *
26
+ * The `inputs` object is copied into the isolate as a global `inputs` variable.
27
+ * The code should return a value or assign to a global `result` variable.
28
+ *
29
+ * Falls back gracefully if `isolated-vm` is not available in the environment.
30
+ */
31
+ export declare function executeSandboxed(code: string, inputs?: Record<string, unknown>, options?: SandboxOptions): Promise<SandboxResult>;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Schema Chunking Tools
3
+ *
4
+ * Tools for extracting and merging chunks of large orbital schemas.
5
+ * Enables LLM-driven schema updates without hitting token limits.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { z } from 'zod';
10
+ export declare function createQuerySchemaStructureTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
11
+ file: z.ZodString;
12
+ }, "strip", z.ZodTypeAny, {
13
+ file: string;
14
+ }, {
15
+ file: string;
16
+ }>, {
17
+ file: string;
18
+ }, {
19
+ file: string;
20
+ }, string, "query_schema_structure">;
21
+ export declare function createExtractChunkTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
22
+ file: z.ZodString;
23
+ type: z.ZodEnum<["orbital", "trait", "inline-trait"]>;
24
+ name: z.ZodString;
25
+ parentOrbital: z.ZodOptional<z.ZodString>;
26
+ includeTraits: z.ZodDefault<z.ZodBoolean>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ type: "orbital" | "trait" | "inline-trait";
29
+ name: string;
30
+ file: string;
31
+ includeTraits: boolean;
32
+ parentOrbital?: string | undefined;
33
+ }, {
34
+ type: "orbital" | "trait" | "inline-trait";
35
+ name: string;
36
+ file: string;
37
+ parentOrbital?: string | undefined;
38
+ includeTraits?: boolean | undefined;
39
+ }>, {
40
+ type: "orbital" | "trait" | "inline-trait";
41
+ name: string;
42
+ file: string;
43
+ includeTraits: boolean;
44
+ parentOrbital?: string | undefined;
45
+ }, {
46
+ type: "orbital" | "trait" | "inline-trait";
47
+ name: string;
48
+ file: string;
49
+ parentOrbital?: string | undefined;
50
+ includeTraits?: boolean | undefined;
51
+ }, string, "extract_chunk">;
52
+ export declare function createApplyChunkTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
53
+ chunkId: z.ZodString;
54
+ }, "strip", z.ZodTypeAny, {
55
+ chunkId: string;
56
+ }, {
57
+ chunkId: string;
58
+ }>, {
59
+ chunkId: string;
60
+ }, {
61
+ chunkId: string;
62
+ }, string, "apply_chunk">;
63
+ export declare function createSchemaChunkingTools(workDir: string): {
64
+ querySchemaStructure: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
65
+ file: z.ZodString;
66
+ }, "strip", z.ZodTypeAny, {
67
+ file: string;
68
+ }, {
69
+ file: string;
70
+ }>, {
71
+ file: string;
72
+ }, {
73
+ file: string;
74
+ }, string, "query_schema_structure">;
75
+ extractChunk: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
76
+ file: z.ZodString;
77
+ type: z.ZodEnum<["orbital", "trait", "inline-trait"]>;
78
+ name: z.ZodString;
79
+ parentOrbital: z.ZodOptional<z.ZodString>;
80
+ includeTraits: z.ZodDefault<z.ZodBoolean>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ type: "orbital" | "trait" | "inline-trait";
83
+ name: string;
84
+ file: string;
85
+ includeTraits: boolean;
86
+ parentOrbital?: string | undefined;
87
+ }, {
88
+ type: "orbital" | "trait" | "inline-trait";
89
+ name: string;
90
+ file: string;
91
+ parentOrbital?: string | undefined;
92
+ includeTraits?: boolean | undefined;
93
+ }>, {
94
+ type: "orbital" | "trait" | "inline-trait";
95
+ name: string;
96
+ file: string;
97
+ includeTraits: boolean;
98
+ parentOrbital?: string | undefined;
99
+ }, {
100
+ type: "orbital" | "trait" | "inline-trait";
101
+ name: string;
102
+ file: string;
103
+ parentOrbital?: string | undefined;
104
+ includeTraits?: boolean | undefined;
105
+ }, string, "extract_chunk">;
106
+ applyChunk: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
107
+ chunkId: z.ZodString;
108
+ }, "strip", z.ZodTypeAny, {
109
+ chunkId: string;
110
+ }, {
111
+ chunkId: string;
112
+ }>, {
113
+ chunkId: string;
114
+ }, {
115
+ chunkId: string;
116
+ }, string, "apply_chunk">;
117
+ };
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Trait Subagent Tool
3
+ *
4
+ * Generates custom trait definitions for orbital schemas.
5
+ * Uses @almadar/llm LLMClient directly.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { z } from 'zod';
10
+ import type { Trait } from '@almadar/core/types';
11
+ import type { SSEEventType } from '../api-types.js';
12
+ export type TraitEventCallback = (traitName: string, traitIndex: number, totalTraits: number, event: {
13
+ type: Exclude<SSEEventType, 'subagent_event'>;
14
+ data: Record<string, unknown>;
15
+ timestamp: number;
16
+ }) => void;
17
+ export type TraitCompleteCallback = (trait: Trait, traitName: string, traitIndex: number, totalTraits: number) => void | Promise<void>;
18
+ export interface TraitSubagentToolOptions {
19
+ onTraitEvent?: TraitEventCallback;
20
+ onTraitComplete?: TraitCompleteCallback;
21
+ }
22
+ export interface TraitSpec {
23
+ name: string;
24
+ description: string;
25
+ category?: string;
26
+ states?: string[];
27
+ events?: string[];
28
+ requiredFields?: Array<{
29
+ name: string;
30
+ type: string;
31
+ description?: string;
32
+ }>;
33
+ needsTicks?: boolean;
34
+ needsEmit?: boolean;
35
+ needsListens?: boolean;
36
+ }
37
+ /**
38
+ * Create a tool for generating custom traits.
39
+ * Uses @almadar/llm LLMClient directly.
40
+ */
41
+ export declare function createTraitSubagentTool(options?: TraitSubagentToolOptions): {
42
+ tool: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
43
+ traitSpec: z.ZodObject<{
44
+ name: z.ZodString;
45
+ description: z.ZodString;
46
+ category: z.ZodOptional<z.ZodString>;
47
+ states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
48
+ events: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
49
+ requiredFields: z.ZodOptional<z.ZodArray<z.ZodObject<{
50
+ name: z.ZodString;
51
+ type: z.ZodString;
52
+ description: z.ZodOptional<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ type: string;
55
+ name: string;
56
+ description?: string | undefined;
57
+ }, {
58
+ type: string;
59
+ name: string;
60
+ description?: string | undefined;
61
+ }>, "many">>;
62
+ needsTicks: z.ZodOptional<z.ZodBoolean>;
63
+ needsEmit: z.ZodOptional<z.ZodBoolean>;
64
+ needsListens: z.ZodOptional<z.ZodBoolean>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ name: string;
67
+ description: string;
68
+ states?: string[] | undefined;
69
+ events?: string[] | undefined;
70
+ category?: string | undefined;
71
+ requiredFields?: {
72
+ type: string;
73
+ name: string;
74
+ description?: string | undefined;
75
+ }[] | undefined;
76
+ needsTicks?: boolean | undefined;
77
+ needsEmit?: boolean | undefined;
78
+ needsListens?: boolean | undefined;
79
+ }, {
80
+ name: string;
81
+ description: string;
82
+ states?: string[] | undefined;
83
+ events?: string[] | undefined;
84
+ category?: string | undefined;
85
+ requiredFields?: {
86
+ type: string;
87
+ name: string;
88
+ description?: string | undefined;
89
+ }[] | undefined;
90
+ needsTicks?: boolean | undefined;
91
+ needsEmit?: boolean | undefined;
92
+ needsListens?: boolean | undefined;
93
+ }>;
94
+ traitIndex: z.ZodOptional<z.ZodNumber>;
95
+ totalTraits: z.ZodOptional<z.ZodNumber>;
96
+ }, "strip", z.ZodTypeAny, {
97
+ traitSpec: {
98
+ name: string;
99
+ description: string;
100
+ states?: string[] | undefined;
101
+ events?: string[] | undefined;
102
+ category?: string | undefined;
103
+ requiredFields?: {
104
+ type: string;
105
+ name: string;
106
+ description?: string | undefined;
107
+ }[] | undefined;
108
+ needsTicks?: boolean | undefined;
109
+ needsEmit?: boolean | undefined;
110
+ needsListens?: boolean | undefined;
111
+ };
112
+ traitIndex?: number | undefined;
113
+ totalTraits?: number | undefined;
114
+ }, {
115
+ traitSpec: {
116
+ name: string;
117
+ description: string;
118
+ states?: string[] | undefined;
119
+ events?: string[] | undefined;
120
+ category?: string | undefined;
121
+ requiredFields?: {
122
+ type: string;
123
+ name: string;
124
+ description?: string | undefined;
125
+ }[] | undefined;
126
+ needsTicks?: boolean | undefined;
127
+ needsEmit?: boolean | undefined;
128
+ needsListens?: boolean | undefined;
129
+ };
130
+ traitIndex?: number | undefined;
131
+ totalTraits?: number | undefined;
132
+ }>, {
133
+ traitSpec: {
134
+ name: string;
135
+ description: string;
136
+ states?: string[] | undefined;
137
+ events?: string[] | undefined;
138
+ category?: string | undefined;
139
+ requiredFields?: {
140
+ type: string;
141
+ name: string;
142
+ description?: string | undefined;
143
+ }[] | undefined;
144
+ needsTicks?: boolean | undefined;
145
+ needsEmit?: boolean | undefined;
146
+ needsListens?: boolean | undefined;
147
+ };
148
+ traitIndex?: number | undefined;
149
+ totalTraits?: number | undefined;
150
+ }, {
151
+ traitSpec: {
152
+ name: string;
153
+ description: string;
154
+ states?: string[] | undefined;
155
+ events?: string[] | undefined;
156
+ category?: string | undefined;
157
+ requiredFields?: {
158
+ type: string;
159
+ name: string;
160
+ description?: string | undefined;
161
+ }[] | undefined;
162
+ needsTicks?: boolean | undefined;
163
+ needsEmit?: boolean | undefined;
164
+ needsListens?: boolean | undefined;
165
+ };
166
+ traitIndex?: number | undefined;
167
+ totalTraits?: number | undefined;
168
+ }, string, "generate_custom_trait">;
169
+ setEventCallback: (callback: TraitEventCallback) => void;
170
+ setTraitCompleteCallback: (callback: TraitCompleteCallback) => void;
171
+ };
172
+ /**
173
+ * Create a helper to wrap trait events into SSE format.
174
+ */
175
+ export declare function createTraitEventWrapper(writeEvent: (event: {
176
+ type: string;
177
+ timestamp: number;
178
+ data: unknown;
179
+ }) => void): TraitEventCallback;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Schema Validation Tool
3
+ *
4
+ * Validates orbital schemas using the @almadar/cli npm package.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import { z } from 'zod';
9
+ /**
10
+ * Create a validate_schema tool that validates schema.orb in the workspace.
11
+ *
12
+ * Uses `npx @almadar/cli validate --json` for comprehensive Rust-based validation.
13
+ *
14
+ * Has a built-in cap of MAX_VALIDATION_ATTEMPTS to prevent
15
+ * infinite validation-fix loops.
16
+ */
17
+ export declare function createValidateSchemaTool(workDir: string): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, string, "validate_schema">;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * @almadar/agent Types
3
+ *
4
+ * Core types for the agent package.
5
+ *
6
+ * LLM access is provided by @almadar/llm (imported directly).
7
+ * Skill prompts are provided by @almadar/skills (imported directly).
8
+ *
9
+ * Only builder-specific modules that don't exist as almadar packages
10
+ * use dependency injection via AgentDependencies.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import type { OrbitalSchema, OrbitalDefinition } from '@almadar/core/types';
15
+ import type { FullOrbitalUnit } from '@almadar/core/types';
16
+ import type { LLMClient } from '@almadar/llm';
17
+ /**
18
+ * Options for combining orbitals into a schema.
19
+ */
20
+ export interface CombinerOptions {
21
+ name: string;
22
+ description?: string;
23
+ version?: string;
24
+ theme?: string;
25
+ defaultRoute?: string;
26
+ validate?: boolean;
27
+ }
28
+ /**
29
+ * Result from combining orbitals.
30
+ */
31
+ export interface CombinerResult {
32
+ success: boolean;
33
+ schema?: OrbitalSchema;
34
+ error?: string;
35
+ stats?: {
36
+ totalOrbitals: number;
37
+ totalEntities: number;
38
+ totalPages: number;
39
+ totalTraits: number;
40
+ };
41
+ validation?: {
42
+ valid: boolean;
43
+ errors: Array<{
44
+ code: string;
45
+ path: string;
46
+ message: string;
47
+ }>;
48
+ warnings: Array<{
49
+ code: string;
50
+ path: string;
51
+ message: string;
52
+ }>;
53
+ };
54
+ }
55
+ /**
56
+ * Function signature for combining orbitals.
57
+ */
58
+ export type CombineOrbitalsFn = (orbitals: FullOrbitalUnit[], options: CombinerOptions) => CombinerResult;
59
+ /**
60
+ * Result from converting domain language to schema.
61
+ */
62
+ export interface DomainConversionResult {
63
+ success: boolean;
64
+ schema?: OrbitalSchema;
65
+ errors?: Array<{
66
+ message: string;
67
+ }>;
68
+ }
69
+ /**
70
+ * Function signature for converting domain text to schema.
71
+ */
72
+ export type ConvertDomainToSchemaFn = (domainText: string, baseSchema: {
73
+ name: string;
74
+ orbitals: unknown[];
75
+ }) => DomainConversionResult;
76
+ /**
77
+ * Log entry from orbital generation.
78
+ */
79
+ export interface GenerationLog {
80
+ level: 'info' | 'warn' | 'error' | 'debug';
81
+ message: string;
82
+ data?: Record<string, unknown>;
83
+ }
84
+ /**
85
+ * Result from orbital generation.
86
+ */
87
+ export interface OrbitalGenerationResult {
88
+ orbital: unknown;
89
+ fingerprint?: string;
90
+ usedTemplate?: boolean;
91
+ usage?: {
92
+ totalTokens: number;
93
+ inputTokens?: number;
94
+ outputTokens?: number;
95
+ };
96
+ validation?: {
97
+ valid: boolean;
98
+ errors?: Array<{
99
+ code: string;
100
+ path: string;
101
+ message: string;
102
+ }>;
103
+ };
104
+ }
105
+ /**
106
+ * Options for orbital generation.
107
+ */
108
+ export interface OrbitalGenerationOptions {
109
+ validate?: boolean;
110
+ requirements?: {
111
+ entities?: string[];
112
+ states?: string[];
113
+ events?: string[];
114
+ guards?: string[];
115
+ pages?: string[];
116
+ effects?: string[];
117
+ rawRequirements?: string[];
118
+ };
119
+ onLog?: (log: GenerationLog) => void;
120
+ }
121
+ /**
122
+ * Function signature for generating a full orbital.
123
+ * Accepts LLMClient from @almadar/llm directly.
124
+ */
125
+ export type GenerateFullOrbitalFn = (client: LLMClient, orbital: OrbitalDefinition, options?: OrbitalGenerationOptions) => Promise<OrbitalGenerationResult>;
126
+ /**
127
+ * @deprecated AgentDependencies is no longer needed. All functions are now
128
+ * internal to @almadar/agent. Import them directly:
129
+ * - combineOrbitals from '@almadar/agent'
130
+ * - convertDomainToSchema from '@almadar/agent'
131
+ * - generateFullOrbital from '@almadar/agent'
132
+ *
133
+ * @example Old (deprecated):
134
+ * ```typescript
135
+ * const deps: AgentDependencies = { ... };
136
+ * const tools = createAgentTools('/workspace', deps);
137
+ * ```
138
+ *
139
+ * @example New:
140
+ * ```typescript
141
+ * import { createAgentTools } from '@almadar/agent';
142
+ * const tools = createAgentTools('/workspace');
143
+ * ```
144
+ */
145
+ export interface AgentDependencies {
146
+ /**
147
+ * @deprecated Use combineOrbitals from '@almadar/agent' instead
148
+ */
149
+ combineOrbitals: CombineOrbitalsFn;
150
+ /**
151
+ * @deprecated Use convertDomainToSchema from '@almadar/agent' instead
152
+ */
153
+ convertDomainToSchema: ConvertDomainToSchemaFn;
154
+ /**
155
+ * @deprecated Use generateFullOrbital from '@almadar/agent' instead
156
+ */
157
+ generateFullOrbital: GenerateFullOrbitalFn;
158
+ }
159
+ /**
160
+ * Subagent configuration.
161
+ * Compatible with the deepagents library SubAgent type.
162
+ */
163
+ export interface SubAgent {
164
+ name: string;
165
+ description: string;
166
+ systemPrompt: string;
167
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * CapabilityToken — HMAC-SHA256 signed scoped token with budget + TTL.
3
+ *
4
+ * TypeScript port of saezbaldo/ic-agi `ic_agi/control_plane.py`.
5
+ * See: https://github.com/saezbaldo/ic-agi
6
+ *
7
+ * TLA+ properties verified in CapabilityTokens.tla:
8
+ * P5 AntiReplay: uses <= budget (invariant)
9
+ * P6 TTLEnforcement: expired tokens produce no log entries
10
+ * P7 RevocationFinality: revoked = true => uses frozen forever
11
+ * P8 BudgetMonotonicity: uses never decreases
12
+ * P9 ForgeryResistance: invalid signature => uses never incremented
13
+ */
14
+ export interface CapabilityToken {
15
+ tokenId: string;
16
+ issuedTo: string;
17
+ /** Sorted alphabetically for determinism. */
18
+ scope: string[];
19
+ /** Unix epoch seconds. */
20
+ issuedAt: number;
21
+ /** Unix epoch seconds. */
22
+ expiresAt: number;
23
+ budget: number;
24
+ uses: number;
25
+ revoked: boolean;
26
+ metadata: Record<string, unknown>;
27
+ /** HMAC-SHA256 hex digest over the immutable fields. */
28
+ signature: string;
29
+ }
30
+ export interface TokenParams {
31
+ issuedTo: string;
32
+ scope: string[];
33
+ ttlSeconds?: number;
34
+ budget?: number;
35
+ criticality?: 'low' | 'medium' | 'high' | 'critical';
36
+ metadata?: Record<string, unknown>;
37
+ }
38
+ /** Issue a new signed capability token. TTL and budget are policy-capped. */
39
+ export declare function issueToken(params: TokenParams, signingKey: Buffer): CapabilityToken;
40
+ /** Verify the token's HMAC signature. Uses constant-time comparison (P9). */
41
+ export declare function verifyToken(token: CapabilityToken, signingKey: Buffer): boolean;
42
+ /** Check if the token can be used (not revoked, not expired, has remaining budget). */
43
+ export declare function isTokenValid(token: CapabilityToken): boolean;
44
+ /**
45
+ * Consume one use from the token.
46
+ * Returns false without mutating if the token is invalid (P5, P8).
47
+ */
48
+ export declare function consumeToken(token: CapabilityToken): boolean;
49
+ /** Permanently revoke a token. Immutable once set (P7). */
50
+ export declare function revokeToken(token: CapabilityToken): void;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * CircuitBreaker — Fault isolation state machine per worker/session.
3
+ *
4
+ * TypeScript port of saezbaldo/ic-agi `ic_agi/circuit_breaker.py`.
5
+ * See: https://github.com/saezbaldo/ic-agi
6
+ *
7
+ * State machine:
8
+ * CLOSED → OPEN when consecutive failures >= threshold OR error rate >= 50%
9
+ * OPEN → HALF_OPEN after recovery timeout (probe request allowed through)
10
+ * HALF_OPEN → CLOSED when consecutive successes >= success threshold
11
+ * HALF_OPEN → OPEN on any failure (immediate trip)
12
+ *
13
+ * Error rate guard only fires when totalRequests >= 5 to prevent
14
+ * tripping on a single noisy startup failure.
15
+ */
16
+ import type { AuditLog } from '../../security/audit-log.js';
17
+ export declare enum CircuitState {
18
+ CLOSED = "CLOSED",
19
+ OPEN = "OPEN",
20
+ HALF_OPEN = "HALF_OPEN"
21
+ }
22
+ export interface CircuitBreakerConfig {
23
+ /** Consecutive failures before tripping. Default: 3 */
24
+ failureThreshold?: number;
25
+ /** Consecutive successes in HALF_OPEN before closing. Default: 2 */
26
+ successThreshold?: number;
27
+ /** Seconds in OPEN before allowing a probe request. Default: 30 */
28
+ recoveryTimeoutSeconds?: number;
29
+ /** Window in seconds for error-rate calculation. Default: 120 */
30
+ errorRateWindow?: number;
31
+ /** Error rate threshold (0–1) to trigger OPEN. Default: 0.5 */
32
+ errorRateThreshold?: number;
33
+ }
34
+ interface WorkerCircuit {
35
+ workerId: string;
36
+ state: CircuitState;
37
+ consecutiveFailures: number;
38
+ consecutiveSuccesses: number;
39
+ totalRequests: number;
40
+ totalFailures: number;
41
+ lastFailureTime: number;
42
+ openedAt: number;
43
+ lastTransitionTime: number;
44
+ /** Sliding window of (timestamp, success) pairs. */
45
+ recent: Array<{
46
+ timestamp: number;
47
+ success: boolean;
48
+ }>;
49
+ }
50
+ export declare class CircuitBreaker {
51
+ private readonly circuits;
52
+ private readonly config;
53
+ private readonly auditLog?;
54
+ constructor(config?: CircuitBreakerConfig, auditLog?: AuditLog);
55
+ private getOrCreate;
56
+ /** Compute error rate for the worker within the configured window. Prunes stale entries. */
57
+ private errorRate;
58
+ private transition;
59
+ /**
60
+ * Check whether the worker is allowed to proceed.
61
+ * - CLOSED: always allowed
62
+ * - OPEN: blocked until recovery timeout, then transitions to HALF_OPEN
63
+ * - HALF_OPEN: probe allowed through
64
+ */
65
+ allow(workerId: string): boolean;
66
+ recordSuccess(workerId: string): void;
67
+ recordFailure(workerId: string): void;
68
+ getState(workerId: string): CircuitState;
69
+ getStats(workerId: string): Pick<WorkerCircuit, 'state' | 'consecutiveFailures' | 'totalRequests' | 'totalFailures'>;
70
+ }
71
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Safety Utilities — IC-AGI TypeScript ports
3
+ *
4
+ * Extracted from the original `src/security/` module.
5
+ * These are standalone safety primitives (circuit breaker, rate limiter,
6
+ * threshold authorization, capability tokens) with no agent-specific deps.
7
+ *
8
+ * See: https://github.com/saezbaldo/ic-agi
9
+ */
10
+ export { AuditLog } from '../../security/audit-log.js';
11
+ export type { AuditEntry } from '../../security/audit-log.js';
12
+ export { issueToken, verifyToken, isTokenValid, consumeToken, revokeToken, } from './capability-token.js';
13
+ export type { CapabilityToken, TokenParams, } from './capability-token.js';
14
+ export { ThresholdAuthorizer } from './threshold-auth.js';
15
+ export type { ApprovalRequest, VoteResult, } from './threshold-auth.js';
16
+ export { RateLimiter } from './rate-limiter.js';
17
+ export type { RateLimitConfig, } from './rate-limiter.js';
18
+ export { CircuitBreaker, CircuitState } from './circuit-breaker.js';
19
+ export type { CircuitBreakerConfig, } from './circuit-breaker.js';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * RateLimiter — Sliding window per-entity rate limiting.
3
+ *
4
+ * TypeScript port of saezbaldo/ic-agi `ic_agi/rate_limiter.py`.
5
+ * See: https://github.com/saezbaldo/ic-agi
6
+ *
7
+ * Two-layer design:
8
+ * 1. Global counter (10x per-entity limit) — system-wide protection
9
+ * 2. Per-(entity, scope) counter — fine-grained per-caller limits
10
+ *
11
+ * Cooldown note: when a per-entity counter is exceeded, a cooldown
12
+ * period is applied. The global counter does not apply cooldown.
13
+ */
14
+ import type { AuditLog } from '../../security/audit-log.js';
15
+ export interface RateLimitConfig {
16
+ /** Maximum requests per window. Default: 20 */
17
+ maxRequests?: number;
18
+ /** Sliding window duration in seconds. Default: 60 */
19
+ windowSeconds?: number;
20
+ /** Cooldown duration in seconds after limit exceeded. Default: 30 */
21
+ cooldownSeconds?: number;
22
+ }
23
+ export declare class RateLimiter {
24
+ private readonly counters;
25
+ private readonly global;
26
+ private readonly config;
27
+ private readonly auditLog?;
28
+ constructor(config?: RateLimitConfig, auditLog?: AuditLog);
29
+ /**
30
+ * Check whether the (entity, scope) pair is allowed to proceed.
31
+ * Checks the global counter first, then the per-entity counter.
32
+ */
33
+ allow(entity: string, scope?: string): boolean;
34
+ remaining(entity: string, scope?: string): number;
35
+ inCooldown(entity: string, scope?: string): boolean;
36
+ reset(entity: string, scope?: string): void;
37
+ /** Reset all counters including global (test utility). */
38
+ resetAll(): void;
39
+ }