@almadar/agent 1.6.4 → 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.
- package/LICENSE +21 -72
- package/README.md +25 -0
- package/dist/agent/event-budget.d.ts +28 -0
- package/dist/agent/experimental/hitl-v2.d.ts +161 -0
- package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
- package/dist/agent/index.d.ts +14 -13
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/interrupt-config.d.ts +51 -0
- package/dist/agent/session-manager.d.ts +204 -0
- package/dist/agent/skill-agent.d.ts +182 -0
- package/dist/agent/workflow-middleware.d.ts +63 -0
- package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
- package/dist/{api-types-CXrq-fts.d.ts → api-types.d.ts} +85 -51
- package/dist/context/compaction.d.ts +191 -0
- package/dist/context-compaction.d.ts +55 -0
- package/dist/evals/online-sampling.d.ts +114 -0
- package/dist/evals/utils/compact-orbital.d.ts +100 -0
- package/dist/event-transformer/event-transformer.d.ts +120 -0
- package/dist/event-transformer/index.d.ts +4 -122
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +58 -1678
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryManager.d.ts +243 -0
- package/dist/memory/PreferenceLearner.d.ts +59 -0
- package/dist/memory/agentic-search.d.ts +116 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/memory-orbital.d.ts +66 -0
- package/dist/memory/types.d.ts +143 -0
- package/dist/metrics.d.ts +77 -0
- package/dist/multi-user.d.ts +155 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/langsmith-integration.d.ts +203 -0
- package/dist/observability.d.ts +196 -0
- package/dist/orbitals/archive/sanitize.d.ts +24 -0
- package/dist/orbitals/batch/batch-generator.d.ts +41 -0
- package/dist/orbitals/batch/concurrency.d.ts +54 -0
- package/dist/orbitals/batch/index.d.ts +14 -0
- package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
- package/dist/orbitals/batch/types.d.ts +103 -0
- package/dist/orbitals/cache/index.d.ts +11 -0
- package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
- package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
- package/dist/orbitals/cache/structural-templates.d.ts +33 -0
- package/dist/orbitals/combiner/index.d.ts +102 -0
- package/dist/orbitals/domain-language/index.d.ts +9 -0
- package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
- package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
- package/dist/orbitals/generation/index.d.ts +10 -0
- package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
- package/dist/orbitals/shared/constants.d.ts +65 -0
- package/dist/orbitals/shared/index.d.ts +11 -0
- package/dist/orbitals/shared/types.d.ts +187 -0
- package/dist/orbitals/shared/utils.d.ts +97 -0
- package/dist/orchestration/complexity-classifier.d.ts +38 -0
- package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
- package/dist/orchestration/index.d.ts +31 -0
- package/dist/orchestration/provider-router.d.ts +45 -0
- package/dist/{firestore-checkpointer-CkNKXoun.d.ts → persistence/firestore-checkpointer.d.ts} +13 -58
- package/dist/persistence/firestore-session-store.d.ts +75 -0
- package/dist/persistence/firestore-store.d.ts +86 -0
- package/dist/persistence/index.d.ts +7 -198
- package/dist/persistence/memory-backend.d.ts +33 -0
- package/dist/persistence/types.d.ts +40 -0
- package/dist/security/audit-log.d.ts +44 -0
- package/dist/state-sync.d.ts +171 -0
- package/dist/subagents.d.ts +38 -0
- package/dist/tools/combine-schemas.d.ts +154 -0
- package/dist/tools/composition.d.ts +119 -0
- package/dist/{orbital-subagent-BdFuf77p.d.ts → tools/domain-orbital.d.ts} +22 -461
- package/dist/tools/execute.d.ts +38 -0
- package/dist/tools/finish-task.d.ts +56 -0
- package/dist/tools/generate-schema.d.ts +53 -0
- package/dist/tools/github.d.ts +297 -0
- package/dist/tools/index.d.ts +1318 -8
- package/dist/tools/orbital-batch-subagent.d.ts +85 -0
- package/dist/tools/orbital-subagent.d.ts +454 -0
- package/dist/tools/orchestrated-fixing.d.ts +74 -0
- package/dist/tools/orchestrated-generation.d.ts +75 -0
- package/dist/tools/sandbox-executor.d.ts +31 -0
- package/dist/tools/schema-chunking.d.ts +117 -0
- package/dist/tools/trait-subagent.d.ts +179 -0
- package/dist/tools/validate-schema.d.ts +17 -0
- package/dist/types.d.ts +14 -17
- package/dist/utils/safety/capability-token.d.ts +50 -0
- package/dist/utils/safety/circuit-breaker.d.ts +71 -0
- package/dist/utils/safety/index.d.ts +19 -0
- package/dist/utils/safety/rate-limiter.d.ts +39 -0
- package/dist/utils/safety/threshold-auth.d.ts +70 -0
- package/dist/workspace/git-client.d.ts +51 -0
- package/dist/workspace/index.d.ts +29 -346
- package/dist/workspace/index.js +39 -0
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/memory-files.d.ts +31 -0
- package/dist/workspace/sink-manager.d.ts +26 -0
- package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
- package/dist/workspace/sinks/git-sink.d.ts +47 -0
- package/dist/workspace/sinks/index.d.ts +9 -0
- package/dist/workspace/templates.d.ts +32 -0
- package/dist/workspace/types.d.ts +86 -0
- package/dist/workspace/workspace-manager.d.ts +57 -0
- package/package.json +12 -10
- package/dist/index-DW3F-Ihx.d.ts +0 -2501
- package/dist/index-DZn69no8.d.ts +0 -1014
|
@@ -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">;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { FullOrbitalUnit, OrbitalSchema, OrbitalDefinition } from '@almadar/core/types';
|
|
2
|
-
import { LLMClient } from '@almadar/llm';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* @almadar/agent Types
|
|
6
3
|
*
|
|
@@ -14,11 +11,13 @@ import { LLMClient } from '@almadar/llm';
|
|
|
14
11
|
*
|
|
15
12
|
* @packageDocumentation
|
|
16
13
|
*/
|
|
17
|
-
|
|
14
|
+
import type { OrbitalSchema, OrbitalDefinition } from '@almadar/core/types';
|
|
15
|
+
import type { FullOrbitalUnit } from '@almadar/core/types';
|
|
16
|
+
import type { LLMClient } from '@almadar/llm';
|
|
18
17
|
/**
|
|
19
18
|
* Options for combining orbitals into a schema.
|
|
20
19
|
*/
|
|
21
|
-
interface CombinerOptions {
|
|
20
|
+
export interface CombinerOptions {
|
|
22
21
|
name: string;
|
|
23
22
|
description?: string;
|
|
24
23
|
version?: string;
|
|
@@ -29,7 +28,7 @@ interface CombinerOptions {
|
|
|
29
28
|
/**
|
|
30
29
|
* Result from combining orbitals.
|
|
31
30
|
*/
|
|
32
|
-
interface CombinerResult {
|
|
31
|
+
export interface CombinerResult {
|
|
33
32
|
success: boolean;
|
|
34
33
|
schema?: OrbitalSchema;
|
|
35
34
|
error?: string;
|
|
@@ -56,11 +55,11 @@ interface CombinerResult {
|
|
|
56
55
|
/**
|
|
57
56
|
* Function signature for combining orbitals.
|
|
58
57
|
*/
|
|
59
|
-
type CombineOrbitalsFn = (orbitals: FullOrbitalUnit[], options: CombinerOptions) => CombinerResult;
|
|
58
|
+
export type CombineOrbitalsFn = (orbitals: FullOrbitalUnit[], options: CombinerOptions) => CombinerResult;
|
|
60
59
|
/**
|
|
61
60
|
* Result from converting domain language to schema.
|
|
62
61
|
*/
|
|
63
|
-
interface DomainConversionResult {
|
|
62
|
+
export interface DomainConversionResult {
|
|
64
63
|
success: boolean;
|
|
65
64
|
schema?: OrbitalSchema;
|
|
66
65
|
errors?: Array<{
|
|
@@ -70,14 +69,14 @@ interface DomainConversionResult {
|
|
|
70
69
|
/**
|
|
71
70
|
* Function signature for converting domain text to schema.
|
|
72
71
|
*/
|
|
73
|
-
type ConvertDomainToSchemaFn = (domainText: string, baseSchema: {
|
|
72
|
+
export type ConvertDomainToSchemaFn = (domainText: string, baseSchema: {
|
|
74
73
|
name: string;
|
|
75
74
|
orbitals: unknown[];
|
|
76
75
|
}) => DomainConversionResult;
|
|
77
76
|
/**
|
|
78
77
|
* Log entry from orbital generation.
|
|
79
78
|
*/
|
|
80
|
-
interface GenerationLog {
|
|
79
|
+
export interface GenerationLog {
|
|
81
80
|
level: 'info' | 'warn' | 'error' | 'debug';
|
|
82
81
|
message: string;
|
|
83
82
|
data?: Record<string, unknown>;
|
|
@@ -85,7 +84,7 @@ interface GenerationLog {
|
|
|
85
84
|
/**
|
|
86
85
|
* Result from orbital generation.
|
|
87
86
|
*/
|
|
88
|
-
interface OrbitalGenerationResult {
|
|
87
|
+
export interface OrbitalGenerationResult {
|
|
89
88
|
orbital: unknown;
|
|
90
89
|
fingerprint?: string;
|
|
91
90
|
usedTemplate?: boolean;
|
|
@@ -106,7 +105,7 @@ interface OrbitalGenerationResult {
|
|
|
106
105
|
/**
|
|
107
106
|
* Options for orbital generation.
|
|
108
107
|
*/
|
|
109
|
-
interface OrbitalGenerationOptions {
|
|
108
|
+
export interface OrbitalGenerationOptions {
|
|
110
109
|
validate?: boolean;
|
|
111
110
|
requirements?: {
|
|
112
111
|
entities?: string[];
|
|
@@ -123,7 +122,7 @@ interface OrbitalGenerationOptions {
|
|
|
123
122
|
* Function signature for generating a full orbital.
|
|
124
123
|
* Accepts LLMClient from @almadar/llm directly.
|
|
125
124
|
*/
|
|
126
|
-
type GenerateFullOrbitalFn = (client: LLMClient, orbital: OrbitalDefinition, options?: OrbitalGenerationOptions) => Promise<OrbitalGenerationResult>;
|
|
125
|
+
export type GenerateFullOrbitalFn = (client: LLMClient, orbital: OrbitalDefinition, options?: OrbitalGenerationOptions) => Promise<OrbitalGenerationResult>;
|
|
127
126
|
/**
|
|
128
127
|
* @deprecated AgentDependencies is no longer needed. All functions are now
|
|
129
128
|
* internal to @almadar/agent. Import them directly:
|
|
@@ -143,7 +142,7 @@ type GenerateFullOrbitalFn = (client: LLMClient, orbital: OrbitalDefinition, opt
|
|
|
143
142
|
* const tools = createAgentTools('/workspace');
|
|
144
143
|
* ```
|
|
145
144
|
*/
|
|
146
|
-
interface AgentDependencies {
|
|
145
|
+
export interface AgentDependencies {
|
|
147
146
|
/**
|
|
148
147
|
* @deprecated Use combineOrbitals from '@almadar/agent' instead
|
|
149
148
|
*/
|
|
@@ -161,10 +160,8 @@ interface AgentDependencies {
|
|
|
161
160
|
* Subagent configuration.
|
|
162
161
|
* Compatible with the deepagents library SubAgent type.
|
|
163
162
|
*/
|
|
164
|
-
interface SubAgent {
|
|
163
|
+
export interface SubAgent {
|
|
165
164
|
name: string;
|
|
166
165
|
description: string;
|
|
167
166
|
systemPrompt: string;
|
|
168
167
|
}
|
|
169
|
-
|
|
170
|
-
export type { AgentDependencies, CombineOrbitalsFn, CombinerOptions, CombinerResult, ConvertDomainToSchemaFn, DomainConversionResult, GenerateFullOrbitalFn, GenerationLog, OrbitalGenerationOptions, OrbitalGenerationResult, SubAgent };
|
|
@@ -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
|
+
}
|