@lobu/core 2.8.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.
Files changed (137) hide show
  1. package/dist/__tests__/encryption.test.d.ts +2 -0
  2. package/dist/__tests__/encryption.test.d.ts.map +1 -0
  3. package/dist/__tests__/encryption.test.js +88 -0
  4. package/dist/__tests__/encryption.test.js.map +1 -0
  5. package/dist/__tests__/fixtures/factories.d.ts +30 -0
  6. package/dist/__tests__/fixtures/factories.d.ts.map +1 -0
  7. package/dist/__tests__/fixtures/factories.js +53 -0
  8. package/dist/__tests__/fixtures/factories.js.map +1 -0
  9. package/dist/__tests__/fixtures/index.d.ts +5 -0
  10. package/dist/__tests__/fixtures/index.d.ts.map +1 -0
  11. package/dist/__tests__/fixtures/index.js +14 -0
  12. package/dist/__tests__/fixtures/index.js.map +1 -0
  13. package/dist/__tests__/fixtures/mock-fetch.d.ts +13 -0
  14. package/dist/__tests__/fixtures/mock-fetch.d.ts.map +1 -0
  15. package/dist/__tests__/fixtures/mock-fetch.js +29 -0
  16. package/dist/__tests__/fixtures/mock-fetch.js.map +1 -0
  17. package/dist/__tests__/fixtures/mock-queue.d.ts +19 -0
  18. package/dist/__tests__/fixtures/mock-queue.d.ts.map +1 -0
  19. package/dist/__tests__/fixtures/mock-queue.js +45 -0
  20. package/dist/__tests__/fixtures/mock-queue.js.map +1 -0
  21. package/dist/__tests__/fixtures/mock-redis.d.ts +54 -0
  22. package/dist/__tests__/fixtures/mock-redis.d.ts.map +1 -0
  23. package/dist/__tests__/fixtures/mock-redis.js +267 -0
  24. package/dist/__tests__/fixtures/mock-redis.js.map +1 -0
  25. package/dist/__tests__/retry.test.d.ts +2 -0
  26. package/dist/__tests__/retry.test.d.ts.map +1 -0
  27. package/dist/__tests__/retry.test.js +114 -0
  28. package/dist/__tests__/retry.test.js.map +1 -0
  29. package/dist/__tests__/sanitize.test.d.ts +2 -0
  30. package/dist/__tests__/sanitize.test.d.ts.map +1 -0
  31. package/dist/__tests__/sanitize.test.js +129 -0
  32. package/dist/__tests__/sanitize.test.js.map +1 -0
  33. package/dist/agent-policy.d.ts +21 -0
  34. package/dist/agent-policy.d.ts.map +1 -0
  35. package/dist/agent-policy.js +181 -0
  36. package/dist/agent-policy.js.map +1 -0
  37. package/dist/agent-store.d.ts +140 -0
  38. package/dist/agent-store.d.ts.map +1 -0
  39. package/dist/agent-store.js +27 -0
  40. package/dist/agent-store.js.map +1 -0
  41. package/dist/api-types.d.ts +213 -0
  42. package/dist/api-types.d.ts.map +1 -0
  43. package/dist/api-types.js +7 -0
  44. package/dist/api-types.js.map +1 -0
  45. package/dist/command-registry.d.ts +41 -0
  46. package/dist/command-registry.d.ts.map +1 -0
  47. package/dist/command-registry.js +43 -0
  48. package/dist/command-registry.js.map +1 -0
  49. package/dist/constants.d.ts +54 -0
  50. package/dist/constants.d.ts.map +1 -0
  51. package/dist/constants.js +60 -0
  52. package/dist/constants.js.map +1 -0
  53. package/dist/errors.d.ts +97 -0
  54. package/dist/errors.d.ts.map +1 -0
  55. package/dist/errors.js +182 -0
  56. package/dist/errors.js.map +1 -0
  57. package/dist/index.d.ts +31 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +64 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/integration-types.d.ts +22 -0
  62. package/dist/integration-types.d.ts.map +1 -0
  63. package/dist/integration-types.js +9 -0
  64. package/dist/integration-types.js.map +1 -0
  65. package/dist/logger.d.ts +15 -0
  66. package/dist/logger.d.ts.map +1 -0
  67. package/dist/logger.js +223 -0
  68. package/dist/logger.js.map +1 -0
  69. package/dist/modules.d.ts +96 -0
  70. package/dist/modules.d.ts.map +1 -0
  71. package/dist/modules.js +140 -0
  72. package/dist/modules.js.map +1 -0
  73. package/dist/otel.d.ts +107 -0
  74. package/dist/otel.d.ts.map +1 -0
  75. package/dist/otel.js +251 -0
  76. package/dist/otel.js.map +1 -0
  77. package/dist/plugin-types.d.ts +42 -0
  78. package/dist/plugin-types.d.ts.map +1 -0
  79. package/dist/plugin-types.js +8 -0
  80. package/dist/plugin-types.js.map +1 -0
  81. package/dist/provider-config-types.d.ts +53 -0
  82. package/dist/provider-config-types.d.ts.map +1 -0
  83. package/dist/provider-config-types.js +7 -0
  84. package/dist/provider-config-types.js.map +1 -0
  85. package/dist/redis/base-store.d.ts +73 -0
  86. package/dist/redis/base-store.d.ts.map +1 -0
  87. package/dist/redis/base-store.js +174 -0
  88. package/dist/redis/base-store.js.map +1 -0
  89. package/dist/sentry.d.ts +12 -0
  90. package/dist/sentry.d.ts.map +1 -0
  91. package/dist/sentry.js +82 -0
  92. package/dist/sentry.js.map +1 -0
  93. package/dist/trace.d.ts +25 -0
  94. package/dist/trace.d.ts.map +1 -0
  95. package/dist/trace.js +32 -0
  96. package/dist/trace.js.map +1 -0
  97. package/dist/types.d.ts +373 -0
  98. package/dist/types.d.ts.map +1 -0
  99. package/dist/types.js +6 -0
  100. package/dist/types.js.map +1 -0
  101. package/dist/utils/encryption.d.ts +9 -0
  102. package/dist/utils/encryption.d.ts.map +1 -0
  103. package/dist/utils/encryption.js +107 -0
  104. package/dist/utils/encryption.js.map +1 -0
  105. package/dist/utils/env.d.ts +20 -0
  106. package/dist/utils/env.d.ts.map +1 -0
  107. package/dist/utils/env.js +50 -0
  108. package/dist/utils/env.js.map +1 -0
  109. package/dist/utils/json.d.ts +11 -0
  110. package/dist/utils/json.d.ts.map +1 -0
  111. package/dist/utils/json.js +38 -0
  112. package/dist/utils/json.js.map +1 -0
  113. package/dist/utils/lock.d.ts +34 -0
  114. package/dist/utils/lock.d.ts.map +1 -0
  115. package/dist/utils/lock.js +66 -0
  116. package/dist/utils/lock.js.map +1 -0
  117. package/dist/utils/mcp-tool-instructions.d.ts +6 -0
  118. package/dist/utils/mcp-tool-instructions.d.ts.map +1 -0
  119. package/dist/utils/mcp-tool-instructions.js +3 -0
  120. package/dist/utils/mcp-tool-instructions.js.map +1 -0
  121. package/dist/utils/retry.d.ts +40 -0
  122. package/dist/utils/retry.d.ts.map +1 -0
  123. package/dist/utils/retry.js +67 -0
  124. package/dist/utils/retry.js.map +1 -0
  125. package/dist/utils/sanitize.d.ts +55 -0
  126. package/dist/utils/sanitize.d.ts.map +1 -0
  127. package/dist/utils/sanitize.js +111 -0
  128. package/dist/utils/sanitize.js.map +1 -0
  129. package/dist/worker/auth.d.ts +34 -0
  130. package/dist/worker/auth.d.ts.map +1 -0
  131. package/dist/worker/auth.js +63 -0
  132. package/dist/worker/auth.js.map +1 -0
  133. package/dist/worker/transport.d.ts +86 -0
  134. package/dist/worker/transport.d.ts.map +1 -0
  135. package/dist/worker/transport.js +13 -0
  136. package/dist/worker/transport.js.map +1 -0
  137. package/package.json +40 -0
package/dist/sentry.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.initSentry = initSentry;
37
+ exports.getSentry = getSentry;
38
+ const logger_1 = require("./logger");
39
+ // Lazy logger initialization to avoid circular dependency
40
+ let _logger = null;
41
+ function getLogger() {
42
+ if (!_logger) {
43
+ _logger = (0, logger_1.createLogger)("sentry");
44
+ }
45
+ return _logger;
46
+ }
47
+ let sentryInstance = null;
48
+ /**
49
+ * Initialize Sentry with configuration from environment variables
50
+ * Falls back to hardcoded DSN if SENTRY_DSN is not provided
51
+ * Uses dynamic import to avoid module resolution issues in dev mode
52
+ */
53
+ async function initSentry() {
54
+ try {
55
+ const Sentry = await Promise.resolve().then(() => __importStar(require("@sentry/node")));
56
+ sentryInstance = Sentry;
57
+ const sentryDsn = process.env.SENTRY_DSN ||
58
+ "https://c5910e58d1a134d64ff93a95a9c535bb@o4507291398897664.ingest.us.sentry.io/4511097466781696";
59
+ Sentry.init({
60
+ dsn: sentryDsn,
61
+ sendDefaultPii: true,
62
+ profileSessionSampleRate: 1.0,
63
+ tracesSampleRate: 1.0, // Capture 100% of traces for better visibility
64
+ integrations: [
65
+ Sentry.consoleLoggingIntegration({ levels: ["log", "warn", "error"] }),
66
+ Sentry.redisIntegration(),
67
+ ],
68
+ });
69
+ getLogger().debug("Sentry monitoring initialized");
70
+ }
71
+ catch (error) {
72
+ getLogger().warn("⚠️ Sentry initialization failed (continuing without monitoring):", error);
73
+ }
74
+ }
75
+ /**
76
+ * Get the initialized Sentry instance
77
+ * @returns Sentry instance or null if not initialized
78
+ */
79
+ function getSentry() {
80
+ return sentryInstance;
81
+ }
82
+ //# sourceMappingURL=sentry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentry.js","sourceRoot":"","sources":["../src/sentry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,gCA2BC;AAMD,8BAEC;AArDD,qCAAqD;AAErD,0DAA0D;AAC1D,IAAI,OAAO,GAAkB,IAAI,CAAC;AAClC,SAAS,SAAS;IAChB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,IAAA,qBAAY,EAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,IAAI,cAAc,GAAyC,IAAI,CAAC;AAEhE;;;;GAIG;AACI,KAAK,UAAU,UAAU;IAC9B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,wDAAa,cAAc,GAAC,CAAC;QAC5C,cAAc,GAAG,MAAM,CAAC;QAExB,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,UAAU;YACtB,iGAAiG,CAAC;QAEpG,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,SAAS;YACd,cAAc,EAAE,IAAI;YACpB,wBAAwB,EAAE,GAAG;YAC7B,gBAAgB,EAAE,GAAG,EAAE,+CAA+C;YACtE,YAAY,EAAE;gBACZ,MAAM,CAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;gBACtE,MAAM,CAAC,gBAAgB,EAAE;aAC1B;SACF,CAAC,CAAC;QAEH,SAAS,EAAE,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,EAAE,CAAC,IAAI,CACd,kEAAkE,EAClE,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS;IACvB,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Trace ID utilities for end-to-end message lifecycle observability.
3
+ * Trace IDs propagate through the entire pipeline:
4
+ * [WhatsApp Message] -> [Queue] -> [Worker Creation] -> [PVC Setup] -> [Agent Runtime] -> [Response]
5
+ *
6
+ * When OpenTelemetry is initialized, spans are sent to Tempo for waterfall visualization.
7
+ * Use createSpan/createChildSpan from ./otel.ts for actual span creation.
8
+ */
9
+ /**
10
+ * Generate a trace ID from a message ID.
11
+ * Format: tr-{messageId prefix}-{timestamp base36}-{random}
12
+ * Example: tr-abc12345-lx4k-a3b2
13
+ */
14
+ export declare function generateTraceId(messageId: string): string;
15
+ /**
16
+ * Extract trace ID from various payload formats.
17
+ * Checks both top-level and nested platformMetadata.
18
+ */
19
+ export declare function extractTraceId(payload: {
20
+ traceId?: string;
21
+ platformMetadata?: {
22
+ traceId?: string;
23
+ };
24
+ }): string | undefined;
25
+ //# sourceMappingURL=trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,GAAG,MAAM,GAAG,SAAS,CAErB"}
package/dist/trace.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Trace ID utilities for end-to-end message lifecycle observability.
4
+ * Trace IDs propagate through the entire pipeline:
5
+ * [WhatsApp Message] -> [Queue] -> [Worker Creation] -> [PVC Setup] -> [Agent Runtime] -> [Response]
6
+ *
7
+ * When OpenTelemetry is initialized, spans are sent to Tempo for waterfall visualization.
8
+ * Use createSpan/createChildSpan from ./otel.ts for actual span creation.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.generateTraceId = generateTraceId;
12
+ exports.extractTraceId = extractTraceId;
13
+ /**
14
+ * Generate a trace ID from a message ID.
15
+ * Format: tr-{messageId prefix}-{timestamp base36}-{random}
16
+ * Example: tr-abc12345-lx4k-a3b2
17
+ */
18
+ function generateTraceId(messageId) {
19
+ const timestamp = Date.now().toString(36);
20
+ const random = Math.random().toString(36).substring(2, 6);
21
+ // Take first 8 chars of messageId, sanitize for safe logging
22
+ const shortMessageId = messageId.replace(/[^a-zA-Z0-9]/g, "").substring(0, 8);
23
+ return `tr-${shortMessageId}-${timestamp}-${random}`;
24
+ }
25
+ /**
26
+ * Extract trace ID from various payload formats.
27
+ * Checks both top-level and nested platformMetadata.
28
+ */
29
+ function extractTraceId(payload) {
30
+ return payload?.traceId || payload?.platformMetadata?.traceId;
31
+ }
32
+ //# sourceMappingURL=trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAOH,0CAMC;AAMD,wCAKC;AAtBD;;;;GAIG;AACH,SAAgB,eAAe,CAAC,SAAiB;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,6DAA6D;IAC7D,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,OAAO,MAAM,cAAc,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAG9B;IACC,OAAO,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC;AAChE,CAAC"}
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Represents a provider installed for a specific agent.
3
+ * Stored in AgentSettings.installedProviders as an ordered array (index 0 = primary).
4
+ */
5
+ export interface InstalledProvider {
6
+ providerId: string;
7
+ installedAt: number;
8
+ config?: {
9
+ baseUrl?: string;
10
+ [key: string]: unknown;
11
+ };
12
+ }
13
+ /**
14
+ * CLI backend configuration for pi-agent integration.
15
+ * Providers can ship CLI tools that pi-agent invokes as backends.
16
+ */
17
+ export interface CliBackendConfig {
18
+ name: string;
19
+ command: string;
20
+ args?: string[];
21
+ env?: Record<string, string>;
22
+ modelArg?: string;
23
+ sessionArg?: string;
24
+ }
25
+ /**
26
+ * Unified authentication profile for any model provider.
27
+ * Stored in AgentSettings.authProfiles as an ordered array (index 0 = primary).
28
+ */
29
+ export interface AuthProfile {
30
+ id: string;
31
+ provider: string;
32
+ model: string;
33
+ credential: string;
34
+ label: string;
35
+ authType: "oauth" | "device-code" | "api-key";
36
+ metadata?: {
37
+ email?: string;
38
+ expiresAt?: number;
39
+ refreshToken?: string;
40
+ accountId?: string;
41
+ };
42
+ createdAt: number;
43
+ }
44
+ export interface SessionContext {
45
+ platform: string;
46
+ channelId: string;
47
+ userId: string;
48
+ messageId: string;
49
+ conversationId?: string;
50
+ teamId?: string;
51
+ userDisplayName?: string;
52
+ workingDirectory?: string;
53
+ customInstructions?: string;
54
+ conversationHistory?: ConversationMessage[];
55
+ }
56
+ export interface ConversationMessage {
57
+ role: "system" | "user" | "assistant";
58
+ content: string;
59
+ timestamp: number;
60
+ }
61
+ /**
62
+ * Per-skill thinking budget level.
63
+ * Controls how much reasoning the model applies when executing a skill.
64
+ */
65
+ export type ThinkingLevel = "off" | "low" | "medium" | "high";
66
+ /**
67
+ * MCP server declared by a skill manifest.
68
+ */
69
+ export interface SkillMcpServer {
70
+ id: string;
71
+ name?: string;
72
+ url?: string;
73
+ type?: "sse" | "stdio";
74
+ command?: string;
75
+ args?: string[];
76
+ oauth?: {
77
+ authUrl: string;
78
+ tokenUrl: string;
79
+ clientId: string;
80
+ clientSecret?: string;
81
+ scopes?: string[];
82
+ grantType?: string;
83
+ responseType?: string;
84
+ };
85
+ resource?: string;
86
+ inputs?: Array<{
87
+ id: string;
88
+ label?: string;
89
+ type?: string;
90
+ }>;
91
+ headers?: Record<string, string>;
92
+ }
93
+ /**
94
+ * Individual skill configuration.
95
+ * Skills are SKILL.md files from GitHub repos that provide instructions to Claude.
96
+ */
97
+ export interface SkillConfig {
98
+ /** Skill repository in owner/repo format (e.g., "anthropics/skills/pdf") */
99
+ repo: string;
100
+ /** Skill name derived from SKILL.md frontmatter or folder name */
101
+ name: string;
102
+ /** Optional description from SKILL.md frontmatter */
103
+ description?: string;
104
+ /** Short always-inlined instruction block for critical rules */
105
+ instructions?: string;
106
+ /** Whether this skill is currently enabled */
107
+ enabled: boolean;
108
+ /** True for system-defined skills (from system-skills.json). Cannot be removed by users. */
109
+ system?: boolean;
110
+ /** Cached SKILL.md content (fetched from GitHub) */
111
+ content?: string;
112
+ /** When the content was last fetched (timestamp ms) */
113
+ contentFetchedAt?: number;
114
+ /** MCP servers declared by the skill */
115
+ mcpServers?: SkillMcpServer[];
116
+ /** System packages declared by the skill (nix) */
117
+ nixPackages?: string[];
118
+ /** Network domains the skill needs access to (legacy flat list) */
119
+ permissions?: string[];
120
+ /** Network access policy declared by the skill */
121
+ networkConfig?: {
122
+ allowedDomains?: string[];
123
+ deniedDomains?: string[];
124
+ };
125
+ /** Tool permission policy declared by the skill */
126
+ toolPermissions?: {
127
+ allow?: string[];
128
+ deny?: string[];
129
+ };
130
+ /** AI providers the skill requires */
131
+ providers?: string[];
132
+ /** Preferred model for this skill (e.g., "anthropic/claude-opus-4") */
133
+ modelPreference?: string;
134
+ /** Thinking level budget for this skill */
135
+ thinkingLevel?: ThinkingLevel;
136
+ }
137
+ /**
138
+ * Skills configuration for agent settings.
139
+ * Contains list of configured skills that can be enabled/disabled.
140
+ */
141
+ export interface SkillsConfig {
142
+ /** List of configured skills */
143
+ skills: SkillConfig[];
144
+ }
145
+ /**
146
+ * Platform-agnostic history message format.
147
+ * Used to pass conversation history to workers.
148
+ */
149
+ export interface HistoryMessage {
150
+ role: "user" | "assistant";
151
+ content: string;
152
+ timestamp: number;
153
+ /** Display name of the message sender */
154
+ userName?: string;
155
+ /** Platform-specific message ID for deduplication */
156
+ messageId?: string;
157
+ }
158
+ /**
159
+ * Network configuration for worker sandbox isolation.
160
+ * Controls which domains the worker can access via HTTP proxy.
161
+ *
162
+ * Filtering rules:
163
+ * - deniedDomains are checked first (take precedence)
164
+ * - allowedDomains are checked second
165
+ * - If neither matches, request is denied
166
+ *
167
+ * Domain pattern format:
168
+ * - "example.com" - exact match
169
+ * - ".example.com" or "*.example.com" - matches subdomains
170
+ */
171
+ export interface NetworkConfig {
172
+ /** Domains the worker is allowed to access. Empty array = no network access. */
173
+ allowedDomains?: string[];
174
+ /** Domains explicitly blocked (takes precedence over allowedDomains). */
175
+ deniedDomains?: string[];
176
+ }
177
+ /**
178
+ * Nix environment configuration for agent workspace.
179
+ * Allows agents to run with specific Nix packages or flakes.
180
+ *
181
+ * Resolution priority:
182
+ * 1. API-provided flakeUrl (highest)
183
+ * 2. API-provided packages
184
+ * 3. flake.nix in git repo
185
+ * 4. shell.nix in git repo
186
+ * 5. .nix-packages file in git repo
187
+ */
188
+ export interface NixConfig {
189
+ /** Nix flake URL (e.g., "github:user/repo#devShell") */
190
+ flakeUrl?: string;
191
+ /** Nixpkgs packages to install (e.g., ["python311", "ffmpeg"]) */
192
+ packages?: string[];
193
+ }
194
+ /**
195
+ * Tool permission configuration for agent settings.
196
+ * Follows Claude Code's permission patterns for consistency.
197
+ *
198
+ * Pattern formats (Claude Code compatible):
199
+ * - "Read" - exact tool match
200
+ * - "Bash(git:*)" - Bash with command filter (only git commands)
201
+ * - "Bash(npm:*)" - Bash with npm commands only
202
+ * - "mcp__servername__*" - all tools from an MCP server
203
+ * - "*" - wildcard (all tools)
204
+ *
205
+ * Filtering rules:
206
+ * - deniedTools are checked first (take precedence)
207
+ * - allowedTools are checked second
208
+ * - If strictMode=true, only allowedTools are permitted
209
+ * - If strictMode=false, defaults + allowedTools are permitted
210
+ */
211
+ export interface ToolsConfig {
212
+ /**
213
+ * Tools to auto-allow (in addition to defaults unless strictMode=true).
214
+ * Supports patterns like "Bash(git:*)" or "mcp__github__*".
215
+ */
216
+ allowedTools?: string[];
217
+ /**
218
+ * Tools to always deny (takes precedence over allowedTools).
219
+ * Use to block specific tools even if they're in defaults.
220
+ */
221
+ deniedTools?: string[];
222
+ /**
223
+ * If true, ONLY allowedTools are permitted (ignores defaults).
224
+ * If false (default), allowedTools are ADDED to default permissions.
225
+ */
226
+ strictMode?: boolean;
227
+ }
228
+ /**
229
+ * MCP server configuration for per-agent MCP servers.
230
+ * Supports both HTTP/SSE and stdio MCP servers.
231
+ */
232
+ export interface McpServerConfig {
233
+ /** For HTTP/SSE MCPs: upstream URL */
234
+ url?: string;
235
+ /** Server type: "sse" for HTTP MCPs, "stdio" for command-based */
236
+ type?: "sse" | "stdio";
237
+ /** For stdio MCPs: command to execute */
238
+ command?: string;
239
+ /** For stdio MCPs: command arguments */
240
+ args?: string[];
241
+ /** For stdio MCPs: environment variables */
242
+ env?: Record<string, string>;
243
+ /** Additional headers for HTTP MCPs */
244
+ headers?: Record<string, string>;
245
+ /** Optional description for the MCP */
246
+ description?: string;
247
+ }
248
+ /**
249
+ * Per-agent MCP configuration.
250
+ * These MCPs are ADDED to global MCPs (not replacing).
251
+ */
252
+ export interface AgentMcpConfig {
253
+ /** Additional MCP servers for this agent */
254
+ mcpServers: Record<string, McpServerConfig>;
255
+ }
256
+ export interface MemoryFlushOptions {
257
+ enabled?: boolean;
258
+ softThresholdTokens?: number;
259
+ systemPrompt?: string;
260
+ prompt?: string;
261
+ }
262
+ export interface AgentCompactionOptions {
263
+ memoryFlush?: MemoryFlushOptions;
264
+ }
265
+ /**
266
+ * Platform-agnostic execution hints passed through gateway → worker.
267
+ * Flexible types (string | string[]) and index signature allow forward
268
+ * compatibility for different agent implementations.
269
+ */
270
+ export interface AgentOptions {
271
+ runtime?: string;
272
+ model?: string;
273
+ maxTokens?: number;
274
+ temperature?: number;
275
+ allowedTools?: string | string[];
276
+ disallowedTools?: string | string[];
277
+ timeoutMinutes?: number | string;
278
+ compaction?: AgentCompactionOptions;
279
+ networkConfig?: Record<string, unknown>;
280
+ envVars?: Record<string, string>;
281
+ [key: string]: unknown;
282
+ }
283
+ /**
284
+ * Platform-agnostic log level type
285
+ * Maps to common logging levels used across different platforms
286
+ */
287
+ export type LogLevel = "debug" | "info" | "warn" | "error";
288
+ /**
289
+ * Context information passed to instruction providers
290
+ */
291
+ export interface InstructionContext {
292
+ userId: string;
293
+ agentId: string;
294
+ sessionKey: string;
295
+ workingDirectory: string;
296
+ availableProjects?: string[];
297
+ userPrompt?: string;
298
+ }
299
+ /**
300
+ * Interface for components that contribute custom instructions
301
+ */
302
+ export interface InstructionProvider {
303
+ /** Unique identifier for this provider */
304
+ name: string;
305
+ /** Priority for ordering (lower = earlier in output) */
306
+ priority: number;
307
+ /**
308
+ * Generate instruction text for this provider
309
+ * @param context - Context information for instruction generation
310
+ * @returns Instruction text or empty string if none
311
+ */
312
+ getInstructions(context: InstructionContext): Promise<string> | string;
313
+ }
314
+ /**
315
+ * Shared payload contract for worker → platform thread responses.
316
+ * Ensures gateway consumers and workers stay type-aligned.
317
+ */
318
+ export interface ThreadResponsePayload {
319
+ messageId: string;
320
+ channelId: string;
321
+ conversationId: string;
322
+ userId: string;
323
+ teamId: string;
324
+ platform?: string;
325
+ content?: string;
326
+ delta?: string;
327
+ isFullReplacement?: boolean;
328
+ processedMessageIds?: string[];
329
+ error?: string;
330
+ errorCode?: string;
331
+ timestamp: number;
332
+ originalMessageId?: string;
333
+ moduleData?: Record<string, unknown>;
334
+ botResponseId?: string;
335
+ ephemeral?: boolean;
336
+ platformMetadata?: Record<string, unknown>;
337
+ statusUpdate?: {
338
+ elapsedSeconds: number;
339
+ state: string;
340
+ };
341
+ execId?: string;
342
+ execStream?: "stdout" | "stderr";
343
+ execExitCode?: number;
344
+ }
345
+ /**
346
+ * Suggested prompt for user
347
+ */
348
+ export interface SuggestedPrompt {
349
+ title: string;
350
+ message: string;
351
+ }
352
+ /**
353
+ * Skill registry entry (global or per-agent).
354
+ */
355
+ export interface RegistryEntry {
356
+ id: string;
357
+ type: string;
358
+ apiUrl: string;
359
+ }
360
+ /**
361
+ * Non-blocking suggestions - agent continues immediately
362
+ * Used for optional next steps
363
+ */
364
+ export interface UserSuggestion {
365
+ id: string;
366
+ userId: string;
367
+ conversationId: string;
368
+ channelId: string;
369
+ teamId?: string;
370
+ blocking: false;
371
+ prompts: SuggestedPrompt[];
372
+ }
373
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAA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AU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,YAAY,CAAC,EAAE;QACb,cAAc,EAAE,MAAM,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,QAAQ,EAAE,KAAK,CAAC;IAEhB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Provider Catalog Types
4
+ // ============================================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Encrypt a string using AES-256-GCM
3
+ */
4
+ export declare function encrypt(text: string): string;
5
+ /**
6
+ * Decrypt a string encrypted with AES-256-GCM
7
+ */
8
+ export declare function decrypt(text: string): string;
9
+ //# sourceMappingURL=encryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AA6CA;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAU5C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAc5C"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.encrypt = encrypt;
37
+ exports.decrypt = decrypt;
38
+ const crypto = __importStar(require("node:crypto"));
39
+ const logger_1 = require("../logger");
40
+ const IV_LENGTH = 12; // 96-bit nonce for AES-GCM
41
+ const logger = (0, logger_1.createLogger)("encryption");
42
+ /**
43
+ * Get encryption key from environment with validation
44
+ *
45
+ * IMPORTANT: The ENCRYPTION_KEY must be exactly 32 bytes (256 bits) for AES-256.
46
+ * Generate a secure key using: `openssl rand -base64 32` or `openssl rand -hex 32`
47
+ */
48
+ function getEncryptionKey() {
49
+ const key = process.env.ENCRYPTION_KEY || "";
50
+ if (!key) {
51
+ throw new Error("ENCRYPTION_KEY environment variable is required for secure operation");
52
+ }
53
+ // Try to decode as base64 first (most common format)
54
+ let keyBuffer;
55
+ try {
56
+ keyBuffer = Buffer.from(key, "base64");
57
+ if (keyBuffer.length === 32) {
58
+ return keyBuffer;
59
+ }
60
+ }
61
+ catch (err) {
62
+ logger.debug("ENCRYPTION_KEY is not valid base64, trying hex format", err);
63
+ }
64
+ // Try as hex (must be exactly 64 hex characters for 32 bytes)
65
+ if (/^[0-9a-fA-F]{64}$/.test(key)) {
66
+ keyBuffer = Buffer.from(key, "hex");
67
+ if (keyBuffer.length === 32) {
68
+ return keyBuffer;
69
+ }
70
+ }
71
+ throw new Error("ENCRYPTION_KEY must be a base64 or hex encoded 32-byte key. " +
72
+ "Generate a valid key with: openssl rand -base64 32");
73
+ }
74
+ /**
75
+ * Encrypt a string using AES-256-GCM
76
+ */
77
+ function encrypt(text) {
78
+ const encryptionKey = getEncryptionKey();
79
+ const iv = crypto.randomBytes(IV_LENGTH);
80
+ const cipher = crypto.createCipheriv("aes-256-gcm", encryptionKey, iv);
81
+ const encrypted = Buffer.concat([
82
+ cipher.update(text, "utf8"),
83
+ cipher.final(),
84
+ ]);
85
+ const tag = cipher.getAuthTag();
86
+ return `${iv.toString("hex")}:${tag.toString("hex")}:${encrypted.toString("hex")}`;
87
+ }
88
+ /**
89
+ * Decrypt a string encrypted with AES-256-GCM
90
+ */
91
+ function decrypt(text) {
92
+ const encryptionKey = getEncryptionKey();
93
+ const parts = text.split(":");
94
+ if (parts.length !== 3)
95
+ throw new Error("Invalid encrypted format");
96
+ const iv = Buffer.from(parts[0], "hex");
97
+ const tag = Buffer.from(parts[1], "hex");
98
+ const encryptedText = Buffer.from(parts[2], "hex");
99
+ const decipher = crypto.createDecipheriv("aes-256-gcm", encryptionKey, iv);
100
+ decipher.setAuthTag(tag);
101
+ const decrypted = Buffer.concat([
102
+ decipher.update(encryptedText),
103
+ decipher.final(),
104
+ ]);
105
+ return decrypted.toString("utf8");
106
+ }
107
+ //# sourceMappingURL=encryption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,0BAUC;AAKD,0BAcC;AA7ED,oDAAsC;AACtC,sCAAyC;AAEzC,MAAM,SAAS,GAAG,EAAE,CAAC,CAAC,2BAA2B;AACjD,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,YAAY,CAAC,CAAC;AAE1C;;;;;GAKG;AACH,SAAS,gBAAgB;IACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;IAC7C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;IACJ,CAAC;IAED,qDAAqD;IACrD,IAAI,SAAiB,CAAC;IACtB,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvC,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YAC5B,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAAC,OAA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