@almadar/agent 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,72 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Almadar FZE
6
+ Licensed Work: KFlow Builder / Almadar
7
+ The Licensed Work is (c) 2025-2026 Almadar FZE.
8
+ Additional Use Grant: You may make production use of the Licensed Work for
9
+ non-commercial purposes and for internal evaluation.
10
+ Production use for commercial purposes requires a
11
+ commercial license from the Licensor.
12
+ Change Date: 2030-02-01
13
+ Change License: Apache License, Version 2.0
14
+
15
+ Terms
16
+
17
+ The Licensor hereby grants you the right to copy, modify, create derivative
18
+ works, redistribute, and make non-production use of the Licensed Work. The
19
+ Licensor may make an Additional Use Grant, above, permitting limited
20
+ production use.
21
+
22
+ Effective on the Change Date, or the fourth anniversary of the first publicly
23
+ available distribution of a specific version of the Licensed Work under this
24
+ License, whichever comes first, the Licensor hereby grants you rights under
25
+ the terms of the Change License, and the rights granted in the paragraph
26
+ above terminate.
27
+
28
+ If your use of the Licensed Work does not comply with the requirements
29
+ currently in effect as described in this License, you must purchase a
30
+ commercial license from the Licensor, its affiliated entities, or authorized
31
+ resellers, or you must refrain from using the Licensed Work.
32
+
33
+ All copies of the original and modified Licensed Work, and derivative works
34
+ of the Licensed Work, are subject to this License. This License applies
35
+ separately for each version of the Licensed Work and the Change Date may vary
36
+ for each version of the Licensed Work released by Licensor.
37
+
38
+ You must conspicuously display this License on each original or modified copy
39
+ of the Licensed Work. If you receive the Licensed Work in original or
40
+ modified form from a third party, the terms and conditions set forth in this
41
+ License apply to your use of that work.
42
+
43
+ Any use of the Licensed Work in violation of this License will automatically
44
+ terminate your rights under this License for the current and all other
45
+ versions of the Licensed Work.
46
+
47
+ This License does not grant you any right in any trademark or logo of
48
+ Licensor or its affiliates (provided that you may use a trademark or logo of
49
+ Licensor as expressly required by this License).
50
+
51
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
52
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
53
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
55
+ TITLE.
56
+
57
+ ---
58
+
59
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
60
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
61
+
62
+ ADDITIONAL TERMS:
63
+
64
+ Documentation (builder/packages/website/docs/) is licensed under CC BY 4.0.
65
+
66
+ TRADEMARKS:
67
+
68
+ "Orbital", "KFlow", "Almadar", and the Almadar logo are trademarks of
69
+ Almadar FZE. You may not use these trademarks without prior written
70
+ permission from Almadar FZE.
71
+
72
+ For licensing inquiries: licensing@almadar.io
@@ -0,0 +1,250 @@
1
+ import { LLMProvider } from '@almadar/llm';
2
+ import { S as SubagentEventCallback, O as OrbitalCompleteCallback, D as DomainOrbitalCompleteCallback } from '../orbital-subagent-BsQBhKzi.js';
3
+ import { BaseCheckpointSaver } from '@langchain/langgraph-checkpoint';
4
+ import { P as PersistenceMode, b as FirestoreDb, d as SessionMetadata, e as SessionRecord } from '../firestore-checkpointer-DxbQ10ve.js';
5
+ export { Command } from '@langchain/langgraph';
6
+ import '@langchain/core/tools';
7
+ import 'zod';
8
+ import '../api-types-BW_58thJ.js';
9
+ import '@langchain/core/runnables';
10
+
11
+ /**
12
+ * Session Manager
13
+ *
14
+ * Unified session management API with pluggable persistence backends.
15
+ * Supports in-memory (development) and Firestore (production) backends.
16
+ */
17
+
18
+ interface SessionManagerOptions {
19
+ /**
20
+ * Persistence mode.
21
+ * @default 'memory'
22
+ */
23
+ mode?: PersistenceMode;
24
+ /**
25
+ * Firestore database instance. Required when mode is 'firestore'.
26
+ */
27
+ firestoreDb?: FirestoreDb;
28
+ }
29
+ /**
30
+ * Unified session management for agent sessions.
31
+ *
32
+ * Handles both session metadata and LangGraph checkpointers.
33
+ */
34
+ declare class SessionManager {
35
+ private mode;
36
+ private memoryBackend;
37
+ private memoryCheckpointers;
38
+ private firestoreCheckpointer;
39
+ private firestoreSessionStore;
40
+ constructor(options?: SessionManagerOptions);
41
+ /**
42
+ * Get the persistence mode.
43
+ */
44
+ getMode(): PersistenceMode;
45
+ /**
46
+ * Get or create a checkpointer for a session.
47
+ */
48
+ getCheckpointer(threadId: string): BaseCheckpointSaver<any>;
49
+ /**
50
+ * Store session metadata.
51
+ */
52
+ store(threadId: string, metadata: SessionMetadata): void;
53
+ /**
54
+ * Get session metadata (sync, memory only).
55
+ */
56
+ get(threadId: string): SessionMetadata | undefined;
57
+ /**
58
+ * Get session metadata (async, supports Firestore).
59
+ */
60
+ getAsync(threadId: string): Promise<SessionMetadata | undefined>;
61
+ /**
62
+ * Clear a session's checkpointer and metadata.
63
+ */
64
+ clear(threadId: string): boolean;
65
+ /**
66
+ * List all sessions (sync, memory only).
67
+ */
68
+ list(): SessionRecord[];
69
+ /**
70
+ * List all sessions (async, supports Firestore).
71
+ */
72
+ listAsync(): Promise<SessionRecord[]>;
73
+ }
74
+
75
+ /**
76
+ * Skill-Based DeepAgent Factory
77
+ *
78
+ * Creates DeepAgent instances that use skills as the primary prompt source.
79
+ * No custom system prompts - all agent behavior is defined through skills.
80
+ *
81
+ * Uses deepagents library primitives:
82
+ * - createDeepAgent() for agent creation
83
+ * - FilesystemBackend for file operations
84
+ *
85
+ * Skill loading is injected via SkillLoader functions, keeping this package
86
+ * independent of any specific skill registry location.
87
+ */
88
+
89
+ /**
90
+ * Skill definition loaded by the consumer.
91
+ */
92
+ interface Skill {
93
+ name: string;
94
+ description: string;
95
+ content: string;
96
+ allowedTools?: string[];
97
+ version?: string;
98
+ references: string[];
99
+ path?: string;
100
+ }
101
+ /**
102
+ * Function to load a skill by name.
103
+ */
104
+ type SkillLoader = (name: string) => Skill | null;
105
+ /**
106
+ * Function to load a skill reference by skill name and ref name.
107
+ */
108
+ type SkillRefLoader = (skillName: string, refName: string) => string | null;
109
+ /**
110
+ * Options for creating a skill agent.
111
+ */
112
+ interface SkillAgentOptions {
113
+ /** Required: The skill(s) to use. Can be a single skill or array of skills. */
114
+ skill: string | string[];
115
+ /** Required: Working directory for the agent */
116
+ workDir: string;
117
+ /** Required: Function to load skills */
118
+ skillLoader: SkillLoader;
119
+ /** Optional: Function to load skill references */
120
+ skillRefLoader?: SkillRefLoader;
121
+ /** Optional: Thread ID for session continuity */
122
+ threadId?: string;
123
+ /** Optional: LLM provider */
124
+ provider?: LLMProvider;
125
+ /** Optional: Model name */
126
+ model?: string;
127
+ /** Optional: Enable verbose logging */
128
+ verbose?: boolean;
129
+ /** Optional: Disable human-in-the-loop interrupts (for eval/testing) */
130
+ noInterrupt?: boolean;
131
+ /** Optional: Callback for subagent events (orbital generation) */
132
+ onSubagentEvent?: SubagentEventCallback;
133
+ /** Optional: Session manager instance (shared across requests) */
134
+ sessionManager?: SessionManager;
135
+ /** Optional: Extracted requirements from analysis phase (for orbital skill) */
136
+ requirements?: {
137
+ entities?: string[];
138
+ states?: string[];
139
+ events?: string[];
140
+ guards?: string[];
141
+ pages?: string[];
142
+ effects?: string[];
143
+ rawRequirements?: string[];
144
+ };
145
+ /** Optional: GitHub integration configuration */
146
+ githubConfig?: {
147
+ /** GitHub personal access token */
148
+ token: string;
149
+ /** Repository owner (e.g., 'octocat') */
150
+ owner?: string;
151
+ /** Repository name (e.g., 'hello-world') */
152
+ repo?: string;
153
+ };
154
+ }
155
+ /**
156
+ * Result from creating a skill agent.
157
+ */
158
+ interface SkillAgentResult {
159
+ /** The agent instance (from deepagents library) */
160
+ agent: any;
161
+ /** Thread ID for session resumption */
162
+ threadId: string;
163
+ /** The loaded skill(s) - primary skill when single, all skills when multiple */
164
+ skill: Skill;
165
+ /** All loaded skills (same as skill when single) */
166
+ skills: Skill[];
167
+ /** Working directory */
168
+ workDir: string;
169
+ /** Orbital tool setter for wiring SSE callback (if orbital tool enabled) */
170
+ setOrbitalEventCallback?: (callback: SubagentEventCallback) => void;
171
+ /** Orbital tool setter for wiring persistence callback */
172
+ setOrbitalCompleteCallback?: (callback: OrbitalCompleteCallback) => void;
173
+ /** Domain orbital callback for lean skill Firestore persistence */
174
+ setDomainCompleteCallback?: (callback: DomainOrbitalCompleteCallback) => void;
175
+ }
176
+ /**
177
+ * Create a skill-based DeepAgent.
178
+ *
179
+ * Uses the specified skill's content as the system prompt.
180
+ * When multiple skills are provided, the agent sees all skill descriptions
181
+ * and can choose the appropriate one based on the user's request.
182
+ *
183
+ * @throws Error if any skill is not found
184
+ */
185
+ declare function createSkillAgent(options: SkillAgentOptions): Promise<SkillAgentResult>;
186
+ /**
187
+ * Resume a skill agent session.
188
+ *
189
+ * Loads the skill from session metadata and creates agent with same threadId.
190
+ *
191
+ * @throws Error if session not found
192
+ */
193
+ declare function resumeSkillAgent(threadId: string, options: {
194
+ verbose?: boolean;
195
+ noInterrupt?: boolean;
196
+ skillLoader: SkillLoader;
197
+ skillRefLoader?: SkillRefLoader;
198
+ sessionManager?: SessionManager;
199
+ }): Promise<SkillAgentResult>;
200
+
201
+ /**
202
+ * Event Budget Configuration
203
+ *
204
+ * Prevents runaway agent loops with soft/hard event limits per skill.
205
+ */
206
+ /**
207
+ * Event budget limits for different skills.
208
+ * - soft: Warning threshold (agent reminded to finish up)
209
+ * - hard: Maximum events before forced completion
210
+ */
211
+ declare const EVENT_BUDGETS: Record<string, {
212
+ soft: number;
213
+ hard: number;
214
+ }>;
215
+ /**
216
+ * Get event budget for a skill.
217
+ */
218
+ declare function getEventBudget(skillName: string): {
219
+ soft: number;
220
+ hard: number;
221
+ };
222
+ /**
223
+ * Generate a budget warning message to inject into the agent.
224
+ */
225
+ declare function getBudgetWarningMessage(eventCount: number, budget: {
226
+ soft: number;
227
+ hard: number;
228
+ }): string | null;
229
+
230
+ /**
231
+ * Interrupt Configuration
232
+ *
233
+ * Human-in-the-loop configuration for agent tools.
234
+ */
235
+ /**
236
+ * Skill metadata (minimal interface for interrupt config).
237
+ */
238
+ interface SkillMeta {
239
+ name: string;
240
+ allowedTools?: string[];
241
+ }
242
+ /**
243
+ * Get interrupt configuration for a skill.
244
+ *
245
+ * Default: require approval for execute tool.
246
+ * Skills can override via frontmatter (future enhancement).
247
+ */
248
+ declare function getInterruptConfig(_skill: SkillMeta): Record<string, boolean>;
249
+
250
+ export { EVENT_BUDGETS, PersistenceMode, SessionManager, type SessionManagerOptions, SessionMetadata, SessionRecord, type Skill, type SkillAgentOptions, type SkillAgentResult, type SkillLoader, type SkillMeta, type SkillRefLoader, createSkillAgent, getBudgetWarningMessage, getEventBudget, getInterruptConfig, resumeSkillAgent };