@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.
- package/LICENSE +374 -0
- package/README.md +594 -0
- package/dist/agents/loopman-agent.d.ts +29 -0
- package/dist/agents/loopman-agent.d.ts.map +1 -0
- package/dist/agents/loopman-agent.js +441 -0
- package/dist/agents/loopman-agent.js.map +1 -0
- package/dist/client/loopman-api.d.ts +123 -0
- package/dist/client/loopman-api.d.ts.map +1 -0
- package/dist/client/loopman-api.js +407 -0
- package/dist/client/loopman-api.js.map +1 -0
- package/dist/helpers/prompt-orchestrator.d.ts +12 -0
- package/dist/helpers/prompt-orchestrator.d.ts.map +1 -0
- package/dist/helpers/prompt-orchestrator.js +133 -0
- package/dist/helpers/prompt-orchestrator.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/loopman-agent-wrapper.d.ts +70 -0
- package/dist/loopman-agent-wrapper.d.ts.map +1 -0
- package/dist/loopman-agent-wrapper.js +157 -0
- package/dist/loopman-agent-wrapper.js.map +1 -0
- package/dist/loopman-middleware.d.ts +78 -0
- package/dist/loopman-middleware.d.ts.map +1 -0
- package/dist/loopman-middleware.js +367 -0
- package/dist/loopman-middleware.js.map +1 -0
- package/dist/mcp/loopman-mcp-client.d.ts +17 -0
- package/dist/mcp/loopman-mcp-client.d.ts.map +1 -0
- package/dist/mcp/loopman-mcp-client.js +76 -0
- package/dist/mcp/loopman-mcp-client.js.map +1 -0
- package/dist/mcp/tool-registry.d.ts +29 -0
- package/dist/mcp/tool-registry.d.ts.map +1 -0
- package/dist/mcp/tool-registry.js +143 -0
- package/dist/mcp/tool-registry.js.map +1 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +9 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/logger.service.d.ts +107 -0
- package/dist/services/logger.service.d.ts.map +1 -0
- package/dist/services/logger.service.js +173 -0
- package/dist/services/logger.service.js.map +1 -0
- package/dist/services/loopman.service.d.ts +72 -0
- package/dist/services/loopman.service.d.ts.map +1 -0
- package/dist/services/loopman.service.js +271 -0
- package/dist/services/loopman.service.js.map +1 -0
- package/dist/services/polling.service.d.ts +136 -0
- package/dist/services/polling.service.d.ts.map +1 -0
- package/dist/services/polling.service.js +428 -0
- package/dist/services/polling.service.js.map +1 -0
- package/dist/types.d.ts +242 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to invoke a LangChain agent with automatic retry on human feedback
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ This is OPTIONAL - use it only if you want automatic retry on feedback.
|
|
6
|
+
* For manual control, just use `agent.invoke()` directly and handle retries yourself.
|
|
7
|
+
*
|
|
8
|
+
* This function monitors agent execution and automatically retries when:
|
|
9
|
+
* - Human provides feedback (NEEDS_CHANGES status)
|
|
10
|
+
* - The middleware injects a SystemMessage asking for retry
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const agent = createAgent({ ... });
|
|
15
|
+
*
|
|
16
|
+
* // Option 1: With auto-retry (helper)
|
|
17
|
+
* const result = await invokeWithRetry(agent, { messages: [...] }, config);
|
|
18
|
+
*
|
|
19
|
+
* // Option 2: Without auto-retry (standard)
|
|
20
|
+
* const result = await agent.invoke({ messages: [...] }, config);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function invokeWithRetry(agent: any, input: any, config?: RunnableConfig, options?: {
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
debug?: boolean;
|
|
26
|
+
}): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to stream a LangChain agent with automatic retry on human feedback
|
|
29
|
+
*
|
|
30
|
+
* ⚠️ This is OPTIONAL - use it only if you want automatic retry on feedback.
|
|
31
|
+
* For manual control, just use `agent.stream()` directly.
|
|
32
|
+
*
|
|
33
|
+
* This function monitors agent streaming and automatically retries when:
|
|
34
|
+
* - Human provides feedback (NEEDS_CHANGES status)
|
|
35
|
+
* - The middleware injects a SystemMessage asking for retry
|
|
36
|
+
*
|
|
37
|
+
* Usage:
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const agent = createAgent({ ... });
|
|
40
|
+
*
|
|
41
|
+
* // Option 1: With auto-retry (helper)
|
|
42
|
+
* for await (const chunk of streamWithRetry(agent, { messages: [...] }, config)) {
|
|
43
|
+
* console.log(chunk);
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* // Option 2: Without auto-retry (standard)
|
|
47
|
+
* for await (const chunk of agent.stream({ messages: [...] }, config)) {
|
|
48
|
+
* console.log(chunk);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function streamWithRetry(agent: any, input: any, config?: RunnableConfig, options?: {
|
|
53
|
+
maxRetries?: number;
|
|
54
|
+
debug?: boolean;
|
|
55
|
+
}): AsyncGenerator<any, void, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* DEPRECATED: Use `invokeWithRetry()` instead for more explicit control
|
|
58
|
+
*
|
|
59
|
+
* Create a wrapped agent that automatically handles Loopman feedback retries
|
|
60
|
+
*
|
|
61
|
+
* ⚠️ Warning: This modifies the agent's invoke() behavior. For less intrusive
|
|
62
|
+
* control, use `invokeWithRetry(agent, input, config, options)` directly.
|
|
63
|
+
*
|
|
64
|
+
* @deprecated Use `invokeWithRetry()` directly instead
|
|
65
|
+
*/
|
|
66
|
+
export declare function createLoopmanAgent(agent: any, options?: {
|
|
67
|
+
maxRetries?: number;
|
|
68
|
+
debug?: boolean;
|
|
69
|
+
}): any;
|
|
70
|
+
//# sourceMappingURL=loopman-agent-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopman-agent-wrapper.d.ts","sourceRoot":"","sources":["../src/loopman-agent-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACA,OAAO,CAAC,GAAG,CAAC,CA0Dd;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAuB,eAAe,CACpC,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACA,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CA+DpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,OAcF"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to invoke a LangChain agent with automatic retry on human feedback
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ This is OPTIONAL - use it only if you want automatic retry on feedback.
|
|
5
|
+
* For manual control, just use `agent.invoke()` directly and handle retries yourself.
|
|
6
|
+
*
|
|
7
|
+
* This function monitors agent execution and automatically retries when:
|
|
8
|
+
* - Human provides feedback (NEEDS_CHANGES status)
|
|
9
|
+
* - The middleware injects a SystemMessage asking for retry
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const agent = createAgent({ ... });
|
|
14
|
+
*
|
|
15
|
+
* // Option 1: With auto-retry (helper)
|
|
16
|
+
* const result = await invokeWithRetry(agent, { messages: [...] }, config);
|
|
17
|
+
*
|
|
18
|
+
* // Option 2: Without auto-retry (standard)
|
|
19
|
+
* const result = await agent.invoke({ messages: [...] }, config);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export async function invokeWithRetry(agent, input, config, options) {
|
|
23
|
+
const maxRetries = options?.maxRetries || 5;
|
|
24
|
+
const debug = options?.debug || false;
|
|
25
|
+
if (debug) {
|
|
26
|
+
console.log("[LoopmanWrapper] Starting agent invocation with auto-retry support");
|
|
27
|
+
}
|
|
28
|
+
// First invocation
|
|
29
|
+
let result = await agent.invoke(input, config);
|
|
30
|
+
// Check if we need to retry (look for SystemMessage with retry instruction)
|
|
31
|
+
let retryCount = 0;
|
|
32
|
+
while (retryCount < maxRetries) {
|
|
33
|
+
const lastMessage = result.messages[result.messages.length - 1];
|
|
34
|
+
const messageType = lastMessage._getType();
|
|
35
|
+
const content = lastMessage.content || "";
|
|
36
|
+
// Check if this is a retry instruction from Loopman middleware
|
|
37
|
+
const needsRetry = messageType === "system" &&
|
|
38
|
+
typeof content === "string" &&
|
|
39
|
+
content.includes("generate a new corrected tool call");
|
|
40
|
+
if (!needsRetry) {
|
|
41
|
+
// No retry needed, return final result
|
|
42
|
+
if (debug) {
|
|
43
|
+
console.log("[LoopmanWrapper] No retry needed, returning result");
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
retryCount++;
|
|
48
|
+
if (debug) {
|
|
49
|
+
console.log(`[LoopmanWrapper] Human feedback detected, retrying (${retryCount}/${maxRetries})...`);
|
|
50
|
+
}
|
|
51
|
+
// Continue the conversation from the current state
|
|
52
|
+
// The agent will see the feedback and SystemMessage, and should generate a corrected tool call
|
|
53
|
+
result = await agent.invoke({
|
|
54
|
+
messages: [], // Empty to continue from checkpointer state
|
|
55
|
+
}, config);
|
|
56
|
+
}
|
|
57
|
+
if (retryCount >= maxRetries) {
|
|
58
|
+
console.warn(`[LoopmanWrapper] Max retries (${maxRetries}) reached. Human feedback may require manual intervention.`);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to stream a LangChain agent with automatic retry on human feedback
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ This is OPTIONAL - use it only if you want automatic retry on feedback.
|
|
66
|
+
* For manual control, just use `agent.stream()` directly.
|
|
67
|
+
*
|
|
68
|
+
* This function monitors agent streaming and automatically retries when:
|
|
69
|
+
* - Human provides feedback (NEEDS_CHANGES status)
|
|
70
|
+
* - The middleware injects a SystemMessage asking for retry
|
|
71
|
+
*
|
|
72
|
+
* Usage:
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const agent = createAgent({ ... });
|
|
75
|
+
*
|
|
76
|
+
* // Option 1: With auto-retry (helper)
|
|
77
|
+
* for await (const chunk of streamWithRetry(agent, { messages: [...] }, config)) {
|
|
78
|
+
* console.log(chunk);
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* // Option 2: Without auto-retry (standard)
|
|
82
|
+
* for await (const chunk of agent.stream({ messages: [...] }, config)) {
|
|
83
|
+
* console.log(chunk);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export async function* streamWithRetry(agent, input, config, options) {
|
|
88
|
+
const maxRetries = options?.maxRetries || 5;
|
|
89
|
+
const debug = options?.debug || false;
|
|
90
|
+
if (debug) {
|
|
91
|
+
console.log("[LoopmanWrapper] Starting agent streaming with auto-retry support");
|
|
92
|
+
}
|
|
93
|
+
let retryCount = 0;
|
|
94
|
+
while (retryCount <= maxRetries) {
|
|
95
|
+
// Collect chunks to detect retry signal
|
|
96
|
+
const chunks = [];
|
|
97
|
+
let needsRetry = false;
|
|
98
|
+
// Stream the agent response
|
|
99
|
+
for await (const chunk of agent.stream(input, config)) {
|
|
100
|
+
chunks.push(chunk);
|
|
101
|
+
yield chunk; // Forward chunk to caller
|
|
102
|
+
// Check if this chunk signals a retry is needed
|
|
103
|
+
if (chunk.messages) {
|
|
104
|
+
const lastMessage = chunk.messages[chunk.messages.length - 1];
|
|
105
|
+
if (lastMessage) {
|
|
106
|
+
const messageType = lastMessage._getType();
|
|
107
|
+
const content = lastMessage.content || "";
|
|
108
|
+
needsRetry =
|
|
109
|
+
messageType === "system" &&
|
|
110
|
+
typeof content === "string" &&
|
|
111
|
+
content.includes("generate a new corrected tool call");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// If no retry needed, we're done
|
|
116
|
+
if (!needsRetry) {
|
|
117
|
+
if (debug) {
|
|
118
|
+
console.log("[LoopmanWrapper] Streaming completed, no retry needed");
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// Retry needed
|
|
123
|
+
retryCount++;
|
|
124
|
+
if (debug) {
|
|
125
|
+
console.log(`[LoopmanWrapper] Human feedback detected in stream, retrying (${retryCount}/${maxRetries})...`);
|
|
126
|
+
}
|
|
127
|
+
if (retryCount > maxRetries) {
|
|
128
|
+
console.warn(`[LoopmanWrapper] Max retries (${maxRetries}) reached during streaming.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// Continue with empty messages (use checkpointer state)
|
|
132
|
+
input = { messages: [] };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* DEPRECATED: Use `invokeWithRetry()` instead for more explicit control
|
|
137
|
+
*
|
|
138
|
+
* Create a wrapped agent that automatically handles Loopman feedback retries
|
|
139
|
+
*
|
|
140
|
+
* ⚠️ Warning: This modifies the agent's invoke() behavior. For less intrusive
|
|
141
|
+
* control, use `invokeWithRetry(agent, input, config, options)` directly.
|
|
142
|
+
*
|
|
143
|
+
* @deprecated Use `invokeWithRetry()` directly instead
|
|
144
|
+
*/
|
|
145
|
+
export function createLoopmanAgent(agent, options) {
|
|
146
|
+
console.warn("[Loopman] createLoopmanAgent() is deprecated. Use invokeWithRetry() for explicit control.");
|
|
147
|
+
return {
|
|
148
|
+
...agent,
|
|
149
|
+
invoke: async (input, config) => {
|
|
150
|
+
return invokeWithRetry(agent, input, config, options);
|
|
151
|
+
},
|
|
152
|
+
// Keep other methods as-is
|
|
153
|
+
stream: agent.stream,
|
|
154
|
+
batch: agent.batch,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=loopman-agent-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopman-agent-wrapper.js","sourceRoot":"","sources":["../src/loopman-agent-wrapper.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAAU,EACV,KAAU,EACV,MAAuB,EACvB,OAGC;IAED,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,KAAK,CAAC;IAEtC,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CACT,oEAAoE,CACrE,CAAC;IACJ,CAAC;IAED,mBAAmB;IACnB,IAAI,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAE/C,4EAA4E;IAC5E,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,OAAO,UAAU,GAAG,UAAU,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAChE,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAA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AAwD;QACxD,KAAK,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAU,EACV,OAGC;IAED,OAAO,CAAC,IAAI,CACV,2FAA2F,CAC5F,CAAC;IACF,OAAO;QACL,GAAG,KAAK;QACR,MAAM,EAAE,KAAK,EAAE,KAAU,EAAE,MAAuB,EAAE,EAAE;YACpD,OAAO,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,2BAA2B;QAC3B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ToolCall } from "@langchain/core/messages";
|
|
2
|
+
import { AgentMiddleware } from "langchain";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for Loopman middleware
|
|
5
|
+
*/
|
|
6
|
+
export interface LoopmanMiddlewareConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Loopman API key
|
|
9
|
+
*/
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/**
|
|
12
|
+
* Workflow ID for organizing decisions in Loopman
|
|
13
|
+
*/
|
|
14
|
+
workflowId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Execution ID (optional, will be auto-generated if not provided)
|
|
17
|
+
*/
|
|
18
|
+
executionId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Channel ID for organizing tasks in Loopman (optional)
|
|
21
|
+
* Used to route tasks to specific channels/teams
|
|
22
|
+
*/
|
|
23
|
+
channelId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Mapping of tool names to interrupt configuration
|
|
26
|
+
* - true: interrupt for all tools calls with this name
|
|
27
|
+
* - false: auto-approve (no human review)
|
|
28
|
+
*/
|
|
29
|
+
interruptOn?: Record<string, boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Timeout for waiting for human decision (in milliseconds)
|
|
32
|
+
* Default: 5 minutes
|
|
33
|
+
*/
|
|
34
|
+
timeout?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Polling interval for checking decision status (in milliseconds)
|
|
37
|
+
* Default: 5 seconds
|
|
38
|
+
*/
|
|
39
|
+
pollingInterval?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Enable debug logging
|
|
42
|
+
*/
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Parent task ID to link tool validation tasks to initial reflection task
|
|
46
|
+
* This creates a hierarchical relationship between the initial human review
|
|
47
|
+
* and subsequent tool validation tasks
|
|
48
|
+
*/
|
|
49
|
+
parentTaskId?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Loopman decision types
|
|
53
|
+
*/
|
|
54
|
+
export type LoopmanDecision = "APPROVED" | "REJECTED" | "MODIFIED";
|
|
55
|
+
/**
|
|
56
|
+
* Loopman middleware for LangChain v1.0
|
|
57
|
+
*
|
|
58
|
+
* Integrates Human-in-the-Loop validation via Loopman platform
|
|
59
|
+
* for tool call validation
|
|
60
|
+
*
|
|
61
|
+
* @example Basic Usage
|
|
62
|
+
* ```typescript
|
|
63
|
+
* loopmanMiddleware({
|
|
64
|
+
* apiKey: process.env.LOOPMAN_API_KEY!,
|
|
65
|
+
* workflowId: "email-workflow",
|
|
66
|
+
* interruptOn: {
|
|
67
|
+
* send_email: true, // Requires validation
|
|
68
|
+
* read_email: false // Auto-approved
|
|
69
|
+
* }
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function loopmanMiddleware(config: LoopmanMiddlewareConfig): AgentMiddleware<any, any, any>;
|
|
74
|
+
/**
|
|
75
|
+
* Export types for external use
|
|
76
|
+
*/
|
|
77
|
+
export type { ToolCall };
|
|
78
|
+
//# sourceMappingURL=loopman-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopman-middleware.d.ts","sourceRoot":"","sources":["../src/loopman-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EAET,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAoB,MAAM,WAAW,CAAC;AAK9D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEtC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CA8chC;AAED;;GAEG;AACH,YAAY,EAAE,QAAQ,EAAE,CAAC"}
|