@almadar/agent 1.3.3 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  import { LLMProvider } from '@almadar/llm';
2
- import { S as SubagentEventCallback, O as OrbitalCompleteCallback, D as DomainOrbitalCompleteCallback } from './orbital-subagent-CCo-ONJY.js';
2
+ import { S as SubagentEventCallback, O as OrbitalCompleteCallback, D as DomainOrbitalCompleteCallback } from './orbital-subagent-CHEeQQr_.js';
3
3
  import { BaseCheckpointSaver } from '@langchain/langgraph-checkpoint';
4
4
  import { P as PersistenceMode, F as FirestoreDb$1, S as SessionMetadata, a as SessionRecord } from './firestore-checkpointer-BkFR-sZM.js';
5
5
  import { OrbitalSchema } from '@almadar/core';
@@ -752,13 +752,49 @@ interface SkillAgentOptions {
752
752
  userId?: string;
753
753
  /** Optional: App ID for project context */
754
754
  appId?: string;
755
+ /** Optional: Tool wrapper for workflow execution (adds retry, telemetry) */
756
+ toolWrapper?: <T extends {
757
+ name: string;
758
+ invoke: (...args: any[]) => Promise<any>;
759
+ }>(tool: T) => T;
760
+ /** Optional: Use orchestrated generation/fixing with complexity-based routing */
761
+ useOrchestration?: boolean;
762
+ }
763
+ /**
764
+ * Agent interface with stream method (simplified from DeepAgent)
765
+ */
766
+ interface SkillAgent {
767
+ stream: (input: {
768
+ messages: Array<{
769
+ role: string;
770
+ content: string;
771
+ }>;
772
+ }, config: {
773
+ configurable: {
774
+ thread_id: string;
775
+ };
776
+ }) => Promise<AsyncIterable<{
777
+ events?: Array<{
778
+ type: string;
779
+ [key: string]: unknown;
780
+ }>;
781
+ model_request?: {
782
+ messages?: Array<{
783
+ kwargs?: {
784
+ content?: Array<{
785
+ type: string;
786
+ }>;
787
+ };
788
+ }>;
789
+ };
790
+ }>>;
755
791
  }
756
792
  /**
757
793
  * Result from creating a skill agent.
758
794
  */
759
795
  interface SkillAgentResult {
760
796
  /** The agent instance (from deepagents library) */
761
- agent: any;
797
+ agent: SkillAgent;
762
798
  /** Thread ID for session resumption */
763
799
  threadId: string;
764
800
  /** The loaded skill(s) - primary skill when single, all skills when multiple */
@@ -838,6 +874,20 @@ declare function getBudgetWarningMessage(eventCount: number, budget: {
838
874
  * Interrupt Configuration
839
875
  *
840
876
  * Human-in-the-loop configuration for agent tools.
877
+ *
878
+ * Threshold-gated actions (require k-of-n approval):
879
+ *
880
+ * | Action | Risk | Gate |
881
+ * |----------------------------------------------|-----------------------|-------|
882
+ * | pnpm publish / npm publish | Irreversible registry | 2-of-2 |
883
+ * | git push to main / production deploy | Live users affected | 2-of-2 |
884
+ * | rm -rf / destructive file ops | Data loss | 2-of-2 |
885
+ * | Database migration / persist delete-all | Production data | 2-of-2 |
886
+ * | Read/write .env, secrets, service accounts | Credential exposure | 2-of-2 |
887
+ * | Cross-user data operations | Privacy violation | 2-of-2 |
888
+ * | Schema deploy to production orbital | Breaking change risk | 1-of-2 |
889
+ *
890
+ * Routine actions (no gate): compile, validate, read files, npm install.
841
891
  */
842
892
  /**
843
893
  * Skill metadata (minimal interface for interrupt config).
@@ -846,6 +896,24 @@ interface SkillMeta {
846
896
  name: string;
847
897
  allowedTools?: string[];
848
898
  }
899
+ /** Risk level of an agent action. */
900
+ type ActionGate = 'none' | 'sensitive' | 'critical';
901
+ /**
902
+ * Maps tool names / command patterns to their required approval gate.
903
+ * Used by the security layer to decide when ThresholdAuthorizer is needed.
904
+ */
905
+ declare const TOOL_GATES: Record<string, ActionGate>;
906
+ /**
907
+ * Command patterns that classify a shell command as critical.
908
+ * Matched against the command string before execution.
909
+ */
910
+ declare const CRITICAL_COMMAND_PATTERNS: RegExp[];
911
+ /**
912
+ * Classify a shell command's risk level.
913
+ * Returns 'critical' if the command matches any CRITICAL_COMMAND_PATTERNS,
914
+ * 'sensitive' otherwise.
915
+ */
916
+ declare function classifyCommand(command: string): ActionGate;
849
917
  /**
850
918
  * Get interrupt configuration for a skill.
851
919
  *
@@ -854,4 +922,92 @@ interface SkillMeta {
854
922
  */
855
923
  declare function getInterruptConfig(_skill: SkillMeta): Record<string, boolean>;
856
924
 
857
- export { type CheckpointRecord as C, DEFAULT_COMPACTION_CONFIG as D, EVENT_BUDGETS as E, type GenerationSession as G, type InterruptRecord as I, MemoryManager as M, type PatternAffinity as P, SessionManager as S, type ToolApprovalPreference as T, type UserPreference as U, type SessionManagerOptions as a, type Skill as b, type SkillAgentOptions as c, type SkillAgentResult as d, type SkillLoader as e, type SkillMeta as f, type SkillRefLoader as g, createSkillAgent as h, getBudgetWarningMessage as i, getEventBudget as j, getInterruptConfig as k, type ContextCompactionConfig as l, type MemoryManagerOptions as m, MemoryOrbitalSchema as n, type ProjectContext as o, type UserFeedback as p, createSummaryPrompt as q, resumeSkillAgent as r, estimateTokens as s, needsCompaction as t };
925
+ /**
926
+ * Workflow Tool Wrapper
927
+ *
928
+ * Wraps tool execution with workflow capabilities:
929
+ * - Retry on failure with exponential backoff
930
+ * - Per-tool telemetry (duration, retries, success/failure)
931
+ * - Timeout handling
932
+ *
933
+ * Usage:
934
+ * ```typescript
935
+ * const wrapper = createWorkflowToolWrapper({ maxRetries: 3 });
936
+ *
937
+ * const { agent } = await createSkillAgent({
938
+ * skill: 'kflow-orbitals',
939
+ * toolWrapper: wrapper.wrap,
940
+ * });
941
+ *
942
+ * // After execution
943
+ * const telemetry = wrapper.getTelemetry();
944
+ * ```
945
+ */
946
+ interface WorkflowToolWrapperOptions {
947
+ /** Max retry attempts per tool (default: 3) */
948
+ maxRetries?: number;
949
+ /** Enable telemetry collection (default: true) */
950
+ enableTelemetry?: boolean;
951
+ /** Max execution time per tool in ms (default: 60000) */
952
+ timeoutMs?: number;
953
+ /** Initial backoff in ms (default: 1000) */
954
+ backoffMs?: number;
955
+ }
956
+ interface ToolTelemetry {
957
+ toolName: string;
958
+ durationMs: number;
959
+ retries: number;
960
+ success: boolean;
961
+ error?: string;
962
+ }
963
+ interface WorkflowToolWrapper {
964
+ /** Wrap a tool with retry/telemetry */
965
+ wrap<T extends {
966
+ name: string;
967
+ invoke: (...args: any[]) => Promise<any>;
968
+ }>(tool: T): T;
969
+ /** Get collected telemetry */
970
+ getTelemetry(): ToolTelemetry[];
971
+ /** Reset telemetry */
972
+ resetTelemetry(): void;
973
+ }
974
+ /**
975
+ * Create a workflow tool wrapper
976
+ *
977
+ * @param options - Wrapper configuration
978
+ * @returns Wrapper with wrap() and getTelemetry() methods
979
+ *
980
+ * @example
981
+ * ```typescript
982
+ * const workflow = createWorkflowToolWrapper({ maxRetries: 3 });
983
+ *
984
+ * const { agent } = await createSkillAgent({
985
+ * skill: 'kflow-orbitals',
986
+ * toolWrapper: workflow.wrap,
987
+ * });
988
+ *
989
+ * // Run agent...
990
+ *
991
+ * // Get results
992
+ * console.log(workflow.getTelemetry());
993
+ * // [{ toolName: 'generate_orbital', durationMs: 5000, retries: 1, success: true }]
994
+ * ```
995
+ */
996
+ declare function createWorkflowToolWrapper(options?: WorkflowToolWrapperOptions): WorkflowToolWrapper;
997
+ /**
998
+ * Create a workflow wrapper specifically for evaluation comparison
999
+ *
1000
+ * This wrapper logs telemetry to console for debugging
1001
+ */
1002
+ declare function createEvalWorkflowWrapper(options?: WorkflowToolWrapperOptions): {
1003
+ wrap: <T extends {
1004
+ name: string;
1005
+ invoke: (...args: any[]) => Promise<any>;
1006
+ }>(tool: T) => T;
1007
+ /** Get collected telemetry */
1008
+ getTelemetry(): ToolTelemetry[];
1009
+ /** Reset telemetry */
1010
+ resetTelemetry(): void;
1011
+ };
1012
+
1013
+ export { type ActionGate as A, estimateTokens as B, CRITICAL_COMMAND_PATTERNS as C, DEFAULT_COMPACTION_CONFIG as D, EVENT_BUDGETS as E, needsCompaction as F, type GenerationSession as G, type InterruptRecord as I, MemoryManager as M, type PatternAffinity as P, SessionManager as S, type ToolTelemetry as T, type UserPreference as U, type WorkflowToolWrapper as W, type SessionManagerOptions as a, type Skill as b, type SkillAgent as c, type SkillAgentOptions as d, type SkillAgentResult as e, type SkillLoader as f, type SkillMeta as g, type SkillRefLoader as h, type WorkflowToolWrapperOptions as i, createEvalWorkflowWrapper as j, createSkillAgent as k, createWorkflowToolWrapper as l, getBudgetWarningMessage as m, getEventBudget as n, getInterruptConfig as o, type CheckpointRecord as p, type ContextCompactionConfig as q, resumeSkillAgent as r, type MemoryManagerOptions as s, MemoryOrbitalSchema as t, type ProjectContext as u, TOOL_GATES as v, type ToolApprovalPreference as w, type UserFeedback as x, classifyCommand as y, createSummaryPrompt as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/agent",
3
- "version": "1.3.3",
3
+ "version": "1.6.1",
4
4
  "description": "AI agent infrastructure for Almadar orbital schema generation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,10 +46,10 @@
46
46
  "uuid": "^9.0.0",
47
47
  "zod": "^3.22.0",
48
48
  "@almadar/core": "1.0.17",
49
- "@almadar/llm": "1.0.16",
50
49
  "@almadar/integrations": "1.0.15",
51
50
  "@almadar/patterns": "1.1.1",
52
- "@almadar/skills": "1.2.2"
51
+ "@almadar/skills": "1.3.0",
52
+ "@almadar/llm": "1.0.17"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@langchain/core": ">=1.0.0",
@@ -71,8 +71,11 @@
71
71
  "optional": false
72
72
  }
73
73
  },
74
+ "optionalDependencies": {
75
+ "isolated-vm": "^4.7.2"
76
+ },
74
77
  "devDependencies": {
75
- "@langchain/core": "^1.1.20",
78
+ "@langchain/core": "^1.1.26",
76
79
  "@langchain/langgraph": "^1.1.4",
77
80
  "@langchain/langgraph-checkpoint": "^1.0.0",
78
81
  "@types/uuid": "^9.0.0",