@loopman/langchain-sdk 1.0.9

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 (55) hide show
  1. package/LICENSE +374 -0
  2. package/README.md +594 -0
  3. package/dist/agents/loopman-agent.d.ts +29 -0
  4. package/dist/agents/loopman-agent.d.ts.map +1 -0
  5. package/dist/agents/loopman-agent.js +441 -0
  6. package/dist/agents/loopman-agent.js.map +1 -0
  7. package/dist/client/loopman-api.d.ts +123 -0
  8. package/dist/client/loopman-api.d.ts.map +1 -0
  9. package/dist/client/loopman-api.js +407 -0
  10. package/dist/client/loopman-api.js.map +1 -0
  11. package/dist/helpers/prompt-orchestrator.d.ts +12 -0
  12. package/dist/helpers/prompt-orchestrator.d.ts.map +1 -0
  13. package/dist/helpers/prompt-orchestrator.js +133 -0
  14. package/dist/helpers/prompt-orchestrator.js.map +1 -0
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +22 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/loopman-agent-wrapper.d.ts +70 -0
  20. package/dist/loopman-agent-wrapper.d.ts.map +1 -0
  21. package/dist/loopman-agent-wrapper.js +157 -0
  22. package/dist/loopman-agent-wrapper.js.map +1 -0
  23. package/dist/loopman-middleware.d.ts +78 -0
  24. package/dist/loopman-middleware.d.ts.map +1 -0
  25. package/dist/loopman-middleware.js +367 -0
  26. package/dist/loopman-middleware.js.map +1 -0
  27. package/dist/mcp/loopman-mcp-client.d.ts +17 -0
  28. package/dist/mcp/loopman-mcp-client.d.ts.map +1 -0
  29. package/dist/mcp/loopman-mcp-client.js +76 -0
  30. package/dist/mcp/loopman-mcp-client.js.map +1 -0
  31. package/dist/mcp/tool-registry.d.ts +29 -0
  32. package/dist/mcp/tool-registry.d.ts.map +1 -0
  33. package/dist/mcp/tool-registry.js +143 -0
  34. package/dist/mcp/tool-registry.js.map +1 -0
  35. package/dist/services/index.d.ts +12 -0
  36. package/dist/services/index.d.ts.map +1 -0
  37. package/dist/services/index.js +9 -0
  38. package/dist/services/index.js.map +1 -0
  39. package/dist/services/logger.service.d.ts +107 -0
  40. package/dist/services/logger.service.d.ts.map +1 -0
  41. package/dist/services/logger.service.js +173 -0
  42. package/dist/services/logger.service.js.map +1 -0
  43. package/dist/services/loopman.service.d.ts +72 -0
  44. package/dist/services/loopman.service.d.ts.map +1 -0
  45. package/dist/services/loopman.service.js +271 -0
  46. package/dist/services/loopman.service.js.map +1 -0
  47. package/dist/services/polling.service.d.ts +136 -0
  48. package/dist/services/polling.service.d.ts.map +1 -0
  49. package/dist/services/polling.service.js +428 -0
  50. package/dist/services/polling.service.js.map +1 -0
  51. package/dist/types.d.ts +242 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +35 -0
  54. package/dist/types.js.map +1 -0
  55. package/package.json +58 -0
@@ -0,0 +1,441 @@
1
+ import { createAgent } from "langchain";
2
+ import { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "../helpers/prompt-orchestrator";
3
+ import { loopmanMiddleware } from "../loopman-middleware";
4
+ import { LoopmanMcpClient } from "../mcp/loopman-mcp-client";
5
+ import { LoopmanToolRegistry } from "../mcp/tool-registry";
6
+ import { LoopmanService } from "../services/loopman.service";
7
+ export class LoopmanAgent {
8
+ config;
9
+ hasFixedExecutionId;
10
+ baseExecutionId;
11
+ maxRetries;
12
+ debug;
13
+ additionalTools;
14
+ agent = null;
15
+ mcpClient;
16
+ toolRegistry;
17
+ loopmanService;
18
+ cachedTools = null;
19
+ middlewareConfig = null; // Store middleware config reference
20
+ constructor(config) {
21
+ this.config = config;
22
+ // If executionId is provided, use it for all invocations (shared context)
23
+ // If not provided, generate a unique executionId per processWithHumanValidation call
24
+ this.hasFixedExecutionId = !!config.executionId;
25
+ this.baseExecutionId = config.executionId;
26
+ this.maxRetries = config.maxRetries ?? 3;
27
+ this.debug = config.debug ?? false;
28
+ this.additionalTools = config.additionalTools ?? [];
29
+ this.mcpClient = new LoopmanMcpClient({
30
+ apiKey: config.apiKey,
31
+ serverUrl: config.mcp?.serverUrl,
32
+ timeoutMs: config.mcp?.timeoutMs,
33
+ });
34
+ // ToolRegistry and LoopmanService will be created per invocation with the correct executionId
35
+ this.toolRegistry = null; // Will be initialized in processWithHumanValidation
36
+ this.loopmanService = null; // Will be initialized in processWithHumanValidation
37
+ }
38
+ async processWithHumanValidation(input) {
39
+ // Generate executionId: use provided one or generate unique per invocation
40
+ const executionId = this.hasFixedExecutionId
41
+ ? this.baseExecutionId
42
+ : `exec-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
43
+ // Initialize services with the correct executionId
44
+ this.toolRegistry = new LoopmanToolRegistry({
45
+ workflowId: this.config.workflowId,
46
+ executionId: executionId,
47
+ category: this.config.category,
48
+ channelId: this.config.channelId,
49
+ debug: this.debug,
50
+ });
51
+ this.loopmanService = new LoopmanService({
52
+ apiKey: this.config.apiKey,
53
+ workflowId: this.config.workflowId,
54
+ executionId: executionId,
55
+ channelId: this.config.channelId,
56
+ timeout: this.config.pollingTimeoutMs,
57
+ pollingInterval: this.config.pollingIntervalMs,
58
+ debug: this.debug,
59
+ });
60
+ let attempt = 0;
61
+ let taskId;
62
+ let feedbackFromHuman;
63
+ while (attempt < this.maxRetries) {
64
+ await this.ensureAgent(executionId, taskId);
65
+ const result = await this.agent.invoke({
66
+ messages: this.buildMessages(input, feedbackFromHuman),
67
+ });
68
+ // Store the conversation history for potential execution after approval
69
+ const conversationHistory = result.messages || [];
70
+ if (this.config.debug) {
71
+ console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
72
+ console.log("🧠 [AGENT REASONING] - Attempt", attempt + 1);
73
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
74
+ // Display all messages to see the agent's reasoning
75
+ if (result.messages &&
76
+ Array.isArray(result.messages)) {
77
+ const messages = result.messages;
78
+ messages.forEach((msg, index) => {
79
+ const role = msg._getType ? msg._getType() : msg.role || "unknown";
80
+ const content = this.normalizeMessageContent(msg.content);
81
+ console.log(`📍 Message ${index + 1} [${role.toUpperCase()}]:`);
82
+ if (content) {
83
+ // Truncate very long content for readability
84
+ const displayContent = content.length > 500
85
+ ? content.substring(0, 500) + "... (truncated)"
86
+ : content;
87
+ console.log(displayContent);
88
+ }
89
+ // Show tool calls if present
90
+ if (msg.tool_calls && msg.tool_calls.length > 0) {
91
+ console.log("\n🔧 Tool Calls:");
92
+ msg.tool_calls.forEach((tc) => {
93
+ console.log(` - ${tc.name}(${JSON.stringify(tc.args).substring(0, 100)}...)`);
94
+ });
95
+ }
96
+ console.log("");
97
+ });
98
+ }
99
+ // Also show intermediate steps if available
100
+ if (result.intermediateSteps &&
101
+ result.intermediateSteps.length > 0) {
102
+ console.log("📊 Intermediate Steps:");
103
+ result.intermediateSteps.forEach((step, index) => {
104
+ console.log(` ${index + 1}. Action: ${step.action?.tool || "unknown"}`);
105
+ if (step.observation) {
106
+ const obs = String(step.observation).substring(0, 100);
107
+ console.log(` Observation: ${obs}...`);
108
+ }
109
+ });
110
+ console.log("");
111
+ }
112
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
113
+ }
114
+ const finalMessage = Array.isArray(result.messages)
115
+ ? result.messages[result.messages.length - 1]
116
+ : undefined;
117
+ const agentOutput = this.normalizeMessageContent(finalMessage?.content);
118
+ const toolCalls = finalMessage?.tool_calls ?? finalMessage?.toolCalls;
119
+ if (this.config.debug && toolCalls) {
120
+ console.log("[LoopmanAgent] Tool calls detected:", JSON.stringify(toolCalls, null, 2));
121
+ }
122
+ const parsedTaskId = extractTaskId(agentOutput ?? "");
123
+ const confidence = agentOutput
124
+ ? extractConfidence(agentOutput)
125
+ : undefined;
126
+ if (!parsedTaskId) {
127
+ return {
128
+ response: agentOutput ?? "",
129
+ status: "completed",
130
+ confidence,
131
+ retries: attempt,
132
+ };
133
+ }
134
+ taskId = parsedTaskId;
135
+ this.loopmanService.logger.setTaskId(taskId);
136
+ // Update middleware config with the new taskId as parentTaskId for future tool calls
137
+ if (this.middlewareConfig) {
138
+ this.middlewareConfig.parentTaskId = taskId;
139
+ if (this.config.debug) {
140
+ console.log(`[LoopmanAgent] Updated middlewareConfig.parentTaskId to: ${taskId}`);
141
+ }
142
+ }
143
+ const decision = await this.loopmanService.polling.waitForDecision({
144
+ taskId: taskId,
145
+ workflowId: this.config.workflowId,
146
+ executionId: executionId,
147
+ apiKey: this.config.apiKey,
148
+ timeoutMs: this.config.pollingTimeoutMs,
149
+ pollingIntervalMs: this.config.pollingIntervalMs,
150
+ debug: this.debug,
151
+ });
152
+ if (this.config.debug) {
153
+ console.log("[LoopmanAgent] Decision received:", JSON.stringify(decision, null, 2));
154
+ }
155
+ if (decision.status === "VALIDATED") {
156
+ // If manualExecutionMode is enabled, just return the approval status
157
+ if (this.config.manualExecutionMode) {
158
+ this.loopmanService.logger.info("Manual execution mode: returning approval status without executing action", { taskId });
159
+ return {
160
+ response: agentOutput ?? "",
161
+ taskId,
162
+ status: "approved",
163
+ confidence,
164
+ decision: {
165
+ taskId,
166
+ status: decision.status,
167
+ feedback: decision.data?.feedback,
168
+ modifiedData: decision.data?.modified_data,
169
+ },
170
+ retries: attempt,
171
+ };
172
+ }
173
+ // Auto-execution mode: execute the approved action
174
+ this.loopmanService.logger.info("Auto-execution mode: executing approved action", { taskId, feedback: decision.data?.feedback });
175
+ // Re-invoke the agent with the full conversation history + execution instruction
176
+ const executionMessages = this.buildExecutionMessages(conversationHistory, decision.data?.feedback, decision.data?.modified_data);
177
+ const executionResult = await this.agent.invoke({
178
+ messages: executionMessages,
179
+ });
180
+ const executionOutput = this.extractAgentOutput(executionResult);
181
+ this.loopmanService.logger.info("Action executed successfully", {
182
+ taskId,
183
+ output: executionOutput,
184
+ });
185
+ return {
186
+ response: executionOutput ?? agentOutput ?? "",
187
+ taskId,
188
+ status: "approved",
189
+ confidence,
190
+ decision: {
191
+ taskId,
192
+ status: decision.status,
193
+ feedback: decision.data?.feedback,
194
+ modifiedData: decision.data?.modified_data,
195
+ },
196
+ retries: attempt,
197
+ };
198
+ }
199
+ if (decision.status === "REFUSED" ||
200
+ decision.status === "CANCELLED" ||
201
+ decision.status === "EXPIRED") {
202
+ return {
203
+ response: agentOutput ?? "",
204
+ taskId,
205
+ status: decision.status === "REFUSED" ? "rejected" : "error",
206
+ confidence,
207
+ decision: {
208
+ taskId,
209
+ status: decision.status,
210
+ feedback: decision.data?.feedback,
211
+ modifiedData: decision.data?.modified_data,
212
+ },
213
+ retries: attempt,
214
+ };
215
+ }
216
+ if (decision.status === "TIMEOUT" || decision.status === "ABORTED") {
217
+ return {
218
+ response: agentOutput ?? "",
219
+ taskId,
220
+ status: decision.status === "TIMEOUT" ? "timeout" : "aborted",
221
+ confidence,
222
+ decision: {
223
+ taskId,
224
+ status: decision.status,
225
+ feedback: decision.data?.feedback,
226
+ modifiedData: decision.data?.modified_data,
227
+ },
228
+ retries: attempt,
229
+ };
230
+ }
231
+ attempt += 1;
232
+ if (attempt >= this.maxRetries) {
233
+ return {
234
+ response: agentOutput ?? "",
235
+ taskId,
236
+ status: "needs_changes",
237
+ confidence,
238
+ decision: {
239
+ taskId,
240
+ status: decision.status,
241
+ feedback: decision.data?.feedback,
242
+ modifiedData: decision.data?.modified_data,
243
+ },
244
+ retries: attempt,
245
+ };
246
+ }
247
+ // Store feedback for next iteration
248
+ feedbackFromHuman = decision.data?.feedback;
249
+ this.loopmanService.logger.info("Human requested changes, retrying agent execution", {
250
+ attempt,
251
+ taskId,
252
+ feedback: feedbackFromHuman,
253
+ });
254
+ }
255
+ return {
256
+ response: "Maximum retries reached without approval",
257
+ taskId,
258
+ status: "needs_changes",
259
+ retries: this.maxRetries,
260
+ };
261
+ }
262
+ async disconnect() {
263
+ await this.mcpClient.disconnect();
264
+ }
265
+ normalizeMessageContent(content) {
266
+ if (content == null) {
267
+ return undefined;
268
+ }
269
+ if (typeof content === "string") {
270
+ return content;
271
+ }
272
+ if (Array.isArray(content)) {
273
+ return content
274
+ .map((part) => typeof part === "string"
275
+ ? part
276
+ : typeof part === "object" && part !== null && "text" in part
277
+ ? String(part.text)
278
+ : "")
279
+ .join("\n");
280
+ }
281
+ if (typeof content === "object" && "text" in content) {
282
+ return String(content.text);
283
+ }
284
+ return String(content);
285
+ }
286
+ async ensureAgent(executionId, taskId) {
287
+ // Always try to reconnect if not connected
288
+ if (!this.mcpClient.isConnected) {
289
+ if (this.config.debug) {
290
+ console.log("[LoopmanAgent] MCP not connected, attempting connection...");
291
+ }
292
+ await this.mcpClient.connect();
293
+ }
294
+ // Always refresh tools to ensure MCP session is alive
295
+ // If the session is dead, this will throw and we'll reconnect
296
+ try {
297
+ const tools = await this.mcpClient.getTools();
298
+ if (this.config.debug) {
299
+ console.log("[LoopmanAgent] MCP tools received:", tools.map((t) => t.name));
300
+ }
301
+ this.cachedTools = this.toolRegistry.toDynamicTools(tools);
302
+ if (this.config.debug) {
303
+ console.log("[LoopmanAgent] MCP tools registered:", this.cachedTools.map((tool) => tool.name));
304
+ }
305
+ }
306
+ catch (error) {
307
+ // MCP session might be dead, try to reconnect
308
+ if (this.config.debug) {
309
+ console.log("[LoopmanAgent] MCP tools retrieval failed, attempting reconnection...", error);
310
+ }
311
+ await this.mcpClient.disconnect();
312
+ await this.mcpClient.connect();
313
+ // Retry getting tools after reconnection
314
+ const tools = await this.mcpClient.getTools();
315
+ if (this.config.debug) {
316
+ console.log("[LoopmanAgent] MCP tools received after reconnection:", tools.map((t) => t.name));
317
+ }
318
+ this.cachedTools = this.toolRegistry.toDynamicTools(tools);
319
+ if (this.config.debug) {
320
+ console.log("[LoopmanAgent] MCP tools registered after reconnection:", this.cachedTools.map((tool) => tool.name));
321
+ }
322
+ }
323
+ const allTools = [...(this.cachedTools ?? []), ...this.additionalTools];
324
+ const prompt = buildLoopmanSystemPrompt({
325
+ workflowId: this.config.workflowId,
326
+ executionId: executionId,
327
+ taskId,
328
+ category: this.config.category,
329
+ systemPrompt: this.config.systemPrompt,
330
+ language: this.config.language,
331
+ });
332
+ if (this.config.debug) {
333
+ console.log("[LoopmanAgent] Final system prompt:\n", prompt);
334
+ }
335
+ // Build middleware configuration if requireApprovalForTools is configured
336
+ const middleware = [];
337
+ if (this.config.requireApprovalForTools &&
338
+ this.config.requireApprovalForTools.length > 0) {
339
+ if (this.config.debug) {
340
+ console.log("[LoopmanAgent] Tool validation middleware enabled for tools:", this.config.requireApprovalForTools);
341
+ }
342
+ // Build interruptOn configuration from requireApprovalForTools
343
+ const interruptOn = {};
344
+ // Special case: ['*'] means all tools require approval
345
+ if (this.config.requireApprovalForTools.includes("*")) {
346
+ // Mark all additional tools (non-MCP) for approval
347
+ for (const tool of this.additionalTools) {
348
+ interruptOn[tool.name] = true;
349
+ }
350
+ }
351
+ else {
352
+ // Mark specific tools for approval
353
+ for (const toolName of this.config.requireApprovalForTools) {
354
+ interruptOn[toolName] = true;
355
+ }
356
+ }
357
+ if (this.config.debug) {
358
+ console.log("[LoopmanAgent] InterruptOn configuration:", interruptOn);
359
+ }
360
+ // Create middleware config and store reference for dynamic updates
361
+ this.middlewareConfig = {
362
+ apiKey: this.config.apiKey,
363
+ workflowId: this.config.workflowId,
364
+ executionId: executionId,
365
+ channelId: this.config.channelId,
366
+ interruptOn,
367
+ timeout: this.config.pollingTimeoutMs,
368
+ pollingInterval: this.config.pollingIntervalMs,
369
+ debug: this.config.debug,
370
+ parentTaskId: taskId, // Link to the initial reflection/validation task
371
+ };
372
+ middleware.push(loopmanMiddleware(this.middlewareConfig));
373
+ }
374
+ this.agent = await createAgent({
375
+ model: this.config.model,
376
+ tools: allTools,
377
+ systemPrompt: prompt,
378
+ middleware: middleware.length > 0 ? middleware : undefined,
379
+ });
380
+ }
381
+ buildMessages(input, feedbackFromHuman) {
382
+ let userContent = input.context
383
+ ? `${input.input}\n\nContext:\n${JSON.stringify(input.context, null, 2)}`
384
+ : input.input;
385
+ // If we have feedback from a previous NEED_CHANGES, include it
386
+ if (feedbackFromHuman) {
387
+ userContent += `\n\n🔄 IMPORTANT - HUMAN FEEDBACK FROM PREVIOUS ATTEMPT:\nThe human reviewer requested changes: "${feedbackFromHuman}"\n\nYou MUST:\n1. Follow the normal workflow (getHumanGuidelines → getDecisionContext)\n2. Analyze the feedback in Step 3\n3. RE-SUBMIT a corrected proposal via submitForHumanReview in Step 4\n\nDo NOT skip Step 4! The human is waiting for your corrected proposal.`;
388
+ }
389
+ return [
390
+ {
391
+ role: "user",
392
+ content: userContent,
393
+ },
394
+ ];
395
+ }
396
+ /**
397
+ * Build execution messages by continuing the conversation history
398
+ * This ensures the agent has full context of what was proposed and approved
399
+ */
400
+ buildExecutionMessages(conversationHistory, feedback, modifiedData) {
401
+ // Start with the full conversation history (includes all context, guidelines, and the submitForHumanReview call)
402
+ const messages = [...conversationHistory];
403
+ // Add a new user message instructing execution
404
+ let executionInstruction = `✅ HUMAN APPROVED YOUR PROPOSAL!\n\nNow execute the actual action you proposed in submitForHumanReview.`;
405
+ if (feedback) {
406
+ executionInstruction += `\n\n💬 Human feedback: "${feedback}"`;
407
+ }
408
+ if (modifiedData) {
409
+ executionInstruction += `\n\n📝 Modified parameters to use:\n${JSON.stringify(modifiedData, null, 2)}`;
410
+ }
411
+ executionInstruction += `\n\n🚨 IMPORTANT:
412
+ - Do NOT call submitForHumanReview again (already approved)
413
+ - Execute the actual tool directly (e.g., send_email)
414
+ - Use the parameters you proposed earlier${modifiedData ? " with the modifications above" : ""}`;
415
+ messages.push({
416
+ role: "user",
417
+ content: executionInstruction,
418
+ });
419
+ return messages;
420
+ }
421
+ extractAgentOutput(result) {
422
+ const messages = result?.messages || [];
423
+ const lastMessage = messages[messages.length - 1];
424
+ if (!lastMessage) {
425
+ return undefined;
426
+ }
427
+ const content = lastMessage.content || lastMessage.kwargs?.content;
428
+ return this.normalizeMessageContent(content);
429
+ }
430
+ }
431
+ export function createLoopmanAgent(config) {
432
+ const { tools, prompt, additionalTools, ...base } = config;
433
+ const mergedTools = [...(additionalTools ?? []), ...(tools ?? [])];
434
+ const loopmanConfig = {
435
+ ...base,
436
+ systemPrompt: config.systemPrompt ?? prompt,
437
+ additionalTools: mergedTools.length > 0 ? mergedTools : undefined,
438
+ };
439
+ return new LoopmanAgent(loopmanConfig);
440
+ }
441
+ //# sourceMappingURL=loopman-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopman-agent.js","sourceRoot":"","sources":["../../src/agents/loopman-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,GACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAQ7D,MAAM,OAAO,YAAY;IAcM;IAbZ,mBAAmB,CAAU;IAC7B,eAAe,CAAU;IACzB,UAAU,CAAS;IACnB,KAAK,CAAU;IACf,eAAe,CAAQ;IAEhC,KAAK,GAAsB,IAAI,CAAC;IAChC,SAAS,CAAmB;IAC5B,YAAY,CAAsB;IAClC,cAAc,CAAiB;IAC/B,WAAW,GAAiB,IAAI,CAAC;IACjC,gBAAgB,GAAQ,IAAI,CAAC,CAAC,oCAAoC;IAE1E,YAA6B,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;QACrD,0EAA0E;QAC1E,qFAAqF;QACrF,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;QAChD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC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;CACF;AAED,MAAM,UAAU,kBAAkB,CAChC,MAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAC3D,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IAEnE,MAAM,aAAa,GAAuB;QACxC,GAAG,IAAI;QACP,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM;QAC3C,eAAe,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;KAClE,CAAC;IAEF,OAAO,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { LoopmanConfig, LoopmanUser } from "../types";
2
+ /**
3
+ * Loopman client for direct API connection
4
+ * Allows authentication with an API key and direct backoffice calls
5
+ */
6
+ export declare class LoopmanApiClient {
7
+ private config;
8
+ private authServiceUrl;
9
+ private tokenCache;
10
+ private readonly bufferTimeSeconds;
11
+ constructor(config: LoopmanConfig);
12
+ /**
13
+ * Exchange an API key for JWT tokens with caching
14
+ * @param apiKey The API key to exchange
15
+ * @returns Object containing accessToken and serverUrl
16
+ */
17
+ getTokenFromApiKey(apiKey: string): Promise<{
18
+ accessToken: string;
19
+ serverUrl: string;
20
+ fromCache: boolean;
21
+ }>;
22
+ /**
23
+ * Get authorization headers with access token and server URL
24
+ */
25
+ private getAuthHeaders;
26
+ /**
27
+ * Get current user from backoffice
28
+ * @param apiKey The API key for authentication
29
+ * @returns Current user information
30
+ */
31
+ getCurrentUser(apiKey: string): Promise<LoopmanUser>;
32
+ /**
33
+ * Generic method to make GET requests to backoffice
34
+ * @param apiKey The API key for authentication
35
+ * @param endpoint The endpoint to call (e.g. '/tasks', '/channels')
36
+ * @returns Response data
37
+ */
38
+ get<T>(apiKey: string, endpoint: string): Promise<T>;
39
+ /**
40
+ * Generic method to make POST requests to backoffice
41
+ * @param apiKey The API key for authentication
42
+ * @param endpoint The endpoint to call
43
+ * @param data The data to send
44
+ * @returns Response data
45
+ */
46
+ post<T>(apiKey: string, endpoint: string, data: any): Promise<T>;
47
+ /**
48
+ * Generic method to make PUT requests to backoffice
49
+ * @param apiKey The API key for authentication
50
+ * @param endpoint The endpoint to call
51
+ * @param data The data to send
52
+ * @returns Response data
53
+ */
54
+ put<T>(apiKey: string, endpoint: string, data: any): Promise<T>;
55
+ /**
56
+ * Generic method to make PATCH requests to backoffice
57
+ * @param apiKey The API key for authentication
58
+ * @param endpoint The endpoint to call
59
+ * @param data The data to send
60
+ * @returns Response data
61
+ */
62
+ patch<T>(apiKey: string, endpoint: string, data: any): Promise<T>;
63
+ /**
64
+ * Generic method to make DELETE requests to backoffice
65
+ * @param apiKey The API key for authentication
66
+ * @param endpoint The endpoint to call
67
+ * @returns Response data
68
+ */
69
+ delete<T>(apiKey: string, endpoint: string): Promise<T>;
70
+ /**
71
+ * Get token from cache if valid, otherwise return null
72
+ */
73
+ private getCachedToken;
74
+ /**
75
+ * Store token in cache with expiration
76
+ */
77
+ private setCachedToken;
78
+ /**
79
+ * Remove a token from cache
80
+ */
81
+ clearCache(apiKey: string): void;
82
+ /**
83
+ * Clear all token cache
84
+ */
85
+ clearAllCache(): void;
86
+ /**
87
+ * Get cache statistics
88
+ */
89
+ getCacheStats(): {
90
+ size: number;
91
+ entries: Array<{
92
+ apiKey: string;
93
+ serverUrl: string;
94
+ expiresAt: string;
95
+ ttl: number;
96
+ }>;
97
+ };
98
+ /**
99
+ * Check if a token exists and is valid
100
+ */
101
+ hasValidToken(apiKey: string): boolean;
102
+ /**
103
+ * Get remaining TTL for a cached token
104
+ */
105
+ getTokenTTL(apiKey: string): number;
106
+ /**
107
+ * Clean up expired tokens from cache
108
+ */
109
+ private cleanupExpiredTokens;
110
+ /**
111
+ * Handle network errors consistently
112
+ */
113
+ private handleNetworkError;
114
+ /**
115
+ * Mask API key for logs (show only first 8 characters)
116
+ */
117
+ private maskApiKey;
118
+ /**
119
+ * Get current configuration
120
+ */
121
+ get configuration(): Readonly<LoopmanConfig>;
122
+ }
123
+ //# sourceMappingURL=loopman-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopman-api.d.ts","sourceRoot":"","sources":["../../src/client/loopman-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAEb,WAAW,EAGZ,MAAM,UAAU,CAAC;AAMlB;;;GAGG;AACH,qBAAa,gBAAgB;IAMf,OAAO,CAAC,MAAM;IAL1B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,UAAU,CACN;IACZ,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAM;gBAEpB,MAAM,EAAE,aAAa;IAQzC;;;;OAIG;IACG,kBAAkB,CACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAqD1E;;OAEG;YACW,cAAc;IAU5B;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA6C1D;;;;;OAKG;IACG,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IA8B1D;;;;;;OAMG;IACG,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAmCtE;;;;;;OAMG;IACG,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC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