@almadar/agent 1.1.3 → 1.1.4

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.
@@ -1,251 +1,12 @@
1
- import { LLMProvider } from '@almadar/llm';
2
- import { S as SubagentEventCallback, O as OrbitalCompleteCallback, D as DomainOrbitalCompleteCallback } from '../orbital-subagent-cNfTLdXQ.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';
1
+ export { E as EVENT_BUDGETS, S as SessionManager, d as SessionManagerOptions, e as Skill, f as SkillAgentOptions, g as SkillAgentResult, h as SkillLoader, i as SkillMeta, j as SkillRefLoader, l as createSkillAgent, m as getBudgetWarningMessage, n as getEventBudget, o as getInterruptConfig, r as resumeSkillAgent } from '../index-wLhxy6Gb.js';
5
2
  export { Command } from '@langchain/langgraph';
3
+ export { P as PersistenceMode, d as SessionMetadata, e as SessionRecord } from '../firestore-checkpointer-DxbQ10ve.js';
4
+ import '@almadar/llm';
5
+ import '../orbital-subagent-cNfTLdXQ.js';
6
6
  import '@langchain/core/tools';
7
7
  import 'zod';
8
8
  import '../api-types-BW_58thJ.js';
9
9
  import '@almadar/core/types';
10
+ import '@langchain/langgraph-checkpoint';
11
+ import '@almadar/core';
10
12
  import '@langchain/core/runnables';
11
-
12
- /**
13
- * Session Manager
14
- *
15
- * Unified session management API with pluggable persistence backends.
16
- * Supports in-memory (development) and Firestore (production) backends.
17
- */
18
-
19
- interface SessionManagerOptions {
20
- /**
21
- * Persistence mode.
22
- * @default 'memory'
23
- */
24
- mode?: PersistenceMode;
25
- /**
26
- * Firestore database instance. Required when mode is 'firestore'.
27
- */
28
- firestoreDb?: FirestoreDb;
29
- }
30
- /**
31
- * Unified session management for agent sessions.
32
- *
33
- * Handles both session metadata and LangGraph checkpointers.
34
- */
35
- declare class SessionManager {
36
- private mode;
37
- private memoryBackend;
38
- private memoryCheckpointers;
39
- private firestoreCheckpointer;
40
- private firestoreSessionStore;
41
- constructor(options?: SessionManagerOptions);
42
- /**
43
- * Get the persistence mode.
44
- */
45
- getMode(): PersistenceMode;
46
- /**
47
- * Get or create a checkpointer for a session.
48
- */
49
- getCheckpointer(threadId: string): BaseCheckpointSaver<any>;
50
- /**
51
- * Store session metadata.
52
- */
53
- store(threadId: string, metadata: SessionMetadata): void;
54
- /**
55
- * Get session metadata (sync, memory only).
56
- */
57
- get(threadId: string): SessionMetadata | undefined;
58
- /**
59
- * Get session metadata (async, supports Firestore).
60
- */
61
- getAsync(threadId: string): Promise<SessionMetadata | undefined>;
62
- /**
63
- * Clear a session's checkpointer and metadata.
64
- */
65
- clear(threadId: string): boolean;
66
- /**
67
- * List all sessions (sync, memory only).
68
- */
69
- list(): SessionRecord[];
70
- /**
71
- * List all sessions (async, supports Firestore).
72
- */
73
- listAsync(): Promise<SessionRecord[]>;
74
- }
75
-
76
- /**
77
- * Skill-Based DeepAgent Factory
78
- *
79
- * Creates DeepAgent instances that use skills as the primary prompt source.
80
- * No custom system prompts - all agent behavior is defined through skills.
81
- *
82
- * Uses deepagents library primitives:
83
- * - createDeepAgent() for agent creation
84
- * - FilesystemBackend for file operations
85
- *
86
- * Skill loading is injected via SkillLoader functions, keeping this package
87
- * independent of any specific skill registry location.
88
- */
89
-
90
- /**
91
- * Skill definition loaded by the consumer.
92
- */
93
- interface Skill {
94
- name: string;
95
- description: string;
96
- content: string;
97
- allowedTools?: string[];
98
- version?: string;
99
- references: string[];
100
- path?: string;
101
- }
102
- /**
103
- * Function to load a skill by name.
104
- */
105
- type SkillLoader = (name: string) => Skill | null;
106
- /**
107
- * Function to load a skill reference by skill name and ref name.
108
- */
109
- type SkillRefLoader = (skillName: string, refName: string) => string | null;
110
- /**
111
- * Options for creating a skill agent.
112
- */
113
- interface SkillAgentOptions {
114
- /** Required: The skill(s) to use. Can be a single skill or array of skills. */
115
- skill: string | string[];
116
- /** Required: Working directory for the agent */
117
- workDir: string;
118
- /** Required: Function to load skills */
119
- skillLoader: SkillLoader;
120
- /** Optional: Function to load skill references */
121
- skillRefLoader?: SkillRefLoader;
122
- /** Optional: Thread ID for session continuity */
123
- threadId?: string;
124
- /** Optional: LLM provider */
125
- provider?: LLMProvider;
126
- /** Optional: Model name */
127
- model?: string;
128
- /** Optional: Enable verbose logging */
129
- verbose?: boolean;
130
- /** Optional: Disable human-in-the-loop interrupts (for eval/testing) */
131
- noInterrupt?: boolean;
132
- /** Optional: Callback for subagent events (orbital generation) */
133
- onSubagentEvent?: SubagentEventCallback;
134
- /** Optional: Session manager instance (shared across requests) */
135
- sessionManager?: SessionManager;
136
- /** Optional: Extracted requirements from analysis phase (for orbital skill) */
137
- requirements?: {
138
- entities?: string[];
139
- states?: string[];
140
- events?: string[];
141
- guards?: string[];
142
- pages?: string[];
143
- effects?: string[];
144
- rawRequirements?: string[];
145
- };
146
- /** Optional: GitHub integration configuration */
147
- githubConfig?: {
148
- /** GitHub personal access token */
149
- token: string;
150
- /** Repository owner (e.g., 'octocat') */
151
- owner?: string;
152
- /** Repository name (e.g., 'hello-world') */
153
- repo?: string;
154
- };
155
- }
156
- /**
157
- * Result from creating a skill agent.
158
- */
159
- interface SkillAgentResult {
160
- /** The agent instance (from deepagents library) */
161
- agent: any;
162
- /** Thread ID for session resumption */
163
- threadId: string;
164
- /** The loaded skill(s) - primary skill when single, all skills when multiple */
165
- skill: Skill;
166
- /** All loaded skills (same as skill when single) */
167
- skills: Skill[];
168
- /** Working directory */
169
- workDir: string;
170
- /** Orbital tool setter for wiring SSE callback (if orbital tool enabled) */
171
- setOrbitalEventCallback?: (callback: SubagentEventCallback) => void;
172
- /** Orbital tool setter for wiring persistence callback */
173
- setOrbitalCompleteCallback?: (callback: OrbitalCompleteCallback) => void;
174
- /** Domain orbital callback for lean skill Firestore persistence */
175
- setDomainCompleteCallback?: (callback: DomainOrbitalCompleteCallback) => void;
176
- }
177
- /**
178
- * Create a skill-based DeepAgent.
179
- *
180
- * Uses the specified skill's content as the system prompt.
181
- * When multiple skills are provided, the agent sees all skill descriptions
182
- * and can choose the appropriate one based on the user's request.
183
- *
184
- * @throws Error if any skill is not found
185
- */
186
- declare function createSkillAgent(options: SkillAgentOptions): Promise<SkillAgentResult>;
187
- /**
188
- * Resume a skill agent session.
189
- *
190
- * Loads the skill from session metadata and creates agent with same threadId.
191
- *
192
- * @throws Error if session not found
193
- */
194
- declare function resumeSkillAgent(threadId: string, options: {
195
- verbose?: boolean;
196
- noInterrupt?: boolean;
197
- skillLoader: SkillLoader;
198
- skillRefLoader?: SkillRefLoader;
199
- sessionManager?: SessionManager;
200
- }): Promise<SkillAgentResult>;
201
-
202
- /**
203
- * Event Budget Configuration
204
- *
205
- * Prevents runaway agent loops with soft/hard event limits per skill.
206
- */
207
- /**
208
- * Event budget limits for different skills.
209
- * - soft: Warning threshold (agent reminded to finish up)
210
- * - hard: Maximum events before forced completion
211
- */
212
- declare const EVENT_BUDGETS: Record<string, {
213
- soft: number;
214
- hard: number;
215
- }>;
216
- /**
217
- * Get event budget for a skill.
218
- */
219
- declare function getEventBudget(skillName: string): {
220
- soft: number;
221
- hard: number;
222
- };
223
- /**
224
- * Generate a budget warning message to inject into the agent.
225
- */
226
- declare function getBudgetWarningMessage(eventCount: number, budget: {
227
- soft: number;
228
- hard: number;
229
- }): string | null;
230
-
231
- /**
232
- * Interrupt Configuration
233
- *
234
- * Human-in-the-loop configuration for agent tools.
235
- */
236
- /**
237
- * Skill metadata (minimal interface for interrupt config).
238
- */
239
- interface SkillMeta {
240
- name: string;
241
- allowedTools?: string[];
242
- }
243
- /**
244
- * Get interrupt configuration for a skill.
245
- *
246
- * Default: require approval for execute tool.
247
- * Skills can override via frontmatter (future enhancement).
248
- */
249
- declare function getInterruptConfig(_skill: SkillMeta): Record<string, boolean>;
250
-
251
- 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 };
@@ -3520,10 +3520,30 @@ ${skillSummaries}
3520
3520
 
3521
3521
  ${skillContents}`;
3522
3522
  }
3523
+ let userPreferences = null;
3524
+ let projectContext = null;
3525
+ if (options.memoryManager && options.userId) {
3526
+ try {
3527
+ userPreferences = await options.memoryManager.getUserPreferences(options.userId);
3528
+ if (userPreferences && verbose) {
3529
+ console.log(`[SkillAgent] Loaded user preferences: ${userPreferences.namingConvention} naming, ${userPreferences.preferredPatterns.length} patterns`);
3530
+ }
3531
+ if (options.appId) {
3532
+ projectContext = await options.memoryManager.getProjectContext(options.appId);
3533
+ if (projectContext && verbose) {
3534
+ console.log(`[SkillAgent] Loaded project context: ${projectContext.existingEntities.length} entities`);
3535
+ }
3536
+ }
3537
+ } catch (error) {
3538
+ console.warn("[SkillAgent] Failed to load memory:", error);
3539
+ }
3540
+ }
3541
+ const memoryContext = buildMemoryContext(userPreferences, projectContext);
3523
3542
  const systemPrompt = [
3524
3543
  BASE_SYSTEM_PROMPT,
3525
3544
  "\n## Skill Instructions\n\n" + skillInstructions,
3526
- references ? "\n## Reference Documentation\n\n" + references : ""
3545
+ references ? "\n## Reference Documentation\n\n" + references : "",
3546
+ memoryContext ? "\n## User Context\n\n" + memoryContext : ""
3527
3547
  ].filter(Boolean).join("\n");
3528
3548
  const threadId = providedThreadId || v4();
3529
3549
  const llmClient = createLLMClient(provider, model, verbose);
@@ -3626,9 +3646,54 @@ ${skillContents}`;
3626
3646
  workDir,
3627
3647
  setOrbitalEventCallback,
3628
3648
  setOrbitalCompleteCallback,
3629
- setDomainCompleteCallback
3649
+ setDomainCompleteCallback,
3650
+ userPreferences,
3651
+ projectContext,
3652
+ memoryManager: options.memoryManager
3630
3653
  };
3631
3654
  }
3655
+ function buildMemoryContext(userPreferences, projectContext) {
3656
+ const sections = [];
3657
+ if (userPreferences) {
3658
+ const prefs = [];
3659
+ if (userPreferences.namingConvention) {
3660
+ prefs.push(`- Preferred naming: ${userPreferences.namingConvention}`);
3661
+ }
3662
+ if (userPreferences.validationStyle) {
3663
+ prefs.push(`- Validation style: ${userPreferences.validationStyle}`);
3664
+ }
3665
+ if (userPreferences.preferredPatterns.length > 0) {
3666
+ prefs.push(`- Preferred patterns: ${userPreferences.preferredPatterns.join(", ")}`);
3667
+ }
3668
+ if (userPreferences.commonEntities.length > 0) {
3669
+ prefs.push(`- Commonly used entities: ${userPreferences.commonEntities.join(", ")}`);
3670
+ }
3671
+ if (prefs.length > 0) {
3672
+ sections.push(`### User Preferences
3673
+ ${prefs.join("\n")}`);
3674
+ }
3675
+ }
3676
+ if (projectContext) {
3677
+ const ctx = [];
3678
+ if (projectContext.projectName) {
3679
+ ctx.push(`- Project: ${projectContext.projectName}`);
3680
+ }
3681
+ if (projectContext.domain) {
3682
+ ctx.push(`- Domain: ${projectContext.domain}`);
3683
+ }
3684
+ if (projectContext.existingEntities.length > 0) {
3685
+ ctx.push(`- Existing entities: ${projectContext.existingEntities.join(", ")}`);
3686
+ }
3687
+ if (projectContext.conventions.length > 0) {
3688
+ ctx.push(`- Project conventions: ${projectContext.conventions.join(", ")}`);
3689
+ }
3690
+ if (ctx.length > 0) {
3691
+ sections.push(`### Project Context
3692
+ ${ctx.join("\n")}`);
3693
+ }
3694
+ }
3695
+ return sections.length > 0 ? sections.join("\n\n") : null;
3696
+ }
3632
3697
  async function resumeSkillAgent(threadId, options) {
3633
3698
  const sessions = options.sessionManager ?? getDefaultSessionManager();
3634
3699
  const metadata = sessions.get(threadId);