@minded-ai/mindedjs 1.0.92 → 1.0.93
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/README.md +1 -1
- package/dist/agent.d.ts +3 -9
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +33 -69
- package/dist/agent.js.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.d.ts +1 -3
- package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.js +38 -5
- package/dist/checkpointer/checkpointSaverFactory.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +1 -8
- package/dist/events/AgentEvents.d.ts.map +1 -1
- package/dist/events/AgentEvents.js +0 -1
- package/dist/events/AgentEvents.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/zendesk.d.ts.map +1 -1
- package/dist/interfaces/zendesk.js +70 -48
- package/dist/interfaces/zendesk.js.map +1 -1
- package/dist/internalTools/appActionRunnerTool.d.ts +1 -2
- package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -1
- package/dist/internalTools/appActionRunnerTool.js +36 -2
- package/dist/internalTools/appActionRunnerTool.js.map +1 -1
- package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.js +61 -0
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
- package/dist/internalTools/timer.d.ts +93 -0
- package/dist/internalTools/timer.d.ts.map +1 -0
- package/dist/internalTools/timer.js +152 -0
- package/dist/internalTools/timer.js.map +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts +1 -3
- package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -1
- package/dist/platform/mindedCheckpointSaver.js +43 -10
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedConnection.d.ts +14 -14
- package/dist/platform/mindedConnection.d.ts.map +1 -1
- package/dist/platform/mindedConnection.js +152 -131
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +38 -38
- package/dist/platform/mindedConnectionTypes.js +24 -24
- package/dist/platform/piiGateway/gateway.d.ts +1 -3
- package/dist/platform/piiGateway/gateway.d.ts.map +1 -1
- package/dist/platform/piiGateway/gateway.js +39 -6
- package/dist/platform/piiGateway/gateway.js.map +1 -1
- package/dist/playbooks/playbooks.d.ts +1 -2
- package/dist/playbooks/playbooks.d.ts.map +1 -1
- package/dist/playbooks/playbooks.js +4 -3
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/voice/voiceSession.d.ts.map +1 -1
- package/dist/voice/voiceSession.js +39 -5
- package/dist/voice/voiceSession.js.map +1 -1
- package/docs/SUMMARY.md +4 -0
- package/docs/tooling/timers.md +61 -0
- package/package.json +3 -4
- package/src/agent.ts +41 -79
- package/src/checkpointer/checkpointSaverFactory.ts +5 -6
- package/src/events/AgentEvents.ts +1 -8
- package/src/index.ts +3 -1
- package/src/interfaces/zendesk.ts +38 -37
- package/src/internalTools/appActionRunnerTool.ts +4 -4
- package/src/internalTools/sendPlaceholderMessage.ts +27 -0
- package/src/internalTools/timer.ts +137 -0
- package/src/platform/mindedCheckpointSaver.ts +27 -27
- package/src/platform/mindedConnection.ts +176 -147
- package/src/platform/mindedConnectionTypes.ts +38 -38
- package/src/platform/piiGateway/gateway.ts +8 -10
- package/src/playbooks/playbooks.ts +5 -5
- package/src/voice/voiceSession.ts +6 -5
- package/docs-structure.md +0 -141
|
@@ -0,0 +1,152 @@
|
|
|
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.timerHandlers = void 0;
|
|
37
|
+
exports.resetTimer = resetTimer;
|
|
38
|
+
exports.cancelTimer = cancelTimer;
|
|
39
|
+
exports.onTimer = onTimer;
|
|
40
|
+
const mindedConnection = __importStar(require("../platform/mindedConnection"));
|
|
41
|
+
const mindedConnectionTypes_1 = require("../platform/mindedConnectionTypes");
|
|
42
|
+
// Store timer handlers by timer name
|
|
43
|
+
exports.timerHandlers = new Map();
|
|
44
|
+
/**
|
|
45
|
+
* Reset or set a timer for a specific session.
|
|
46
|
+
* When the timer expires, all registered timer handlers will be called.
|
|
47
|
+
*
|
|
48
|
+
* @param params - The timer configuration
|
|
49
|
+
* @param params.sessionId - The session ID to associate the timer with
|
|
50
|
+
* @param params.seconds - Number of seconds until the timer expires
|
|
51
|
+
* @param params.timerName - Unique name for this timer (used for cancellation and identification)
|
|
52
|
+
* @param params.eventArgs - Additional data to pass to the timer handler when it triggers
|
|
53
|
+
* @returns Promise resolving to timer reset response
|
|
54
|
+
* @throws {Error} When the Minded connection is not established
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { resetTimer } from '@minded-ai/mindedjs';
|
|
59
|
+
*
|
|
60
|
+
* // Set a timer to follow up in 10 seconds
|
|
61
|
+
* await resetTimer({
|
|
62
|
+
* sessionId: 'session-123',
|
|
63
|
+
* seconds: 10,
|
|
64
|
+
* timerName: 'followup',
|
|
65
|
+
* payload: {
|
|
66
|
+
* message: 'Are you still there?'
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
async function resetTimer({ sessionId, seconds, timerName, payload = {} }) {
|
|
72
|
+
return await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.TIMER_RESET, {
|
|
73
|
+
sessionId,
|
|
74
|
+
seconds,
|
|
75
|
+
timerName,
|
|
76
|
+
eventArgs: payload,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Cancel an existing timer for a specific session.
|
|
81
|
+
*
|
|
82
|
+
* @param sessionId - The session ID the timer is associated with
|
|
83
|
+
* @param timerName - The name of the timer to cancel
|
|
84
|
+
* @returns Promise resolving to timer cancel response
|
|
85
|
+
* @throws {Error} When the Minded connection is not established
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { cancelTimer } from '@minded-ai/mindedjs';
|
|
90
|
+
*
|
|
91
|
+
* // Cancel a previously set timer
|
|
92
|
+
* await cancelTimer('session-123', 'followup');
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
async function cancelTimer(sessionId, timerName) {
|
|
96
|
+
if (!mindedConnection.isConnected()) {
|
|
97
|
+
throw new Error('Minded connection is not established when trying to cancel timer');
|
|
98
|
+
}
|
|
99
|
+
return await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.TIMER_CANCEL, {
|
|
100
|
+
sessionId,
|
|
101
|
+
timerName,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Register a handler for timer trigger events for a specific timer name.
|
|
106
|
+
* The handler will be called when the specified timer expires for any session.
|
|
107
|
+
*
|
|
108
|
+
* @param params - The configuration for the timer handler
|
|
109
|
+
* @param params.timerName - The name of the timer to handle
|
|
110
|
+
* @param params.handler - Function to call when the timer triggers
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { onTimer } from '@minded-ai/mindedjs';
|
|
115
|
+
*
|
|
116
|
+
* // Register a handler for the 'followup' timer
|
|
117
|
+
* onTimer({
|
|
118
|
+
* timerName: 'followup',
|
|
119
|
+
* handler: async ({ sessionId, payload }) => {
|
|
120
|
+
* console.log(`Followup timer triggered for session ${sessionId}`);
|
|
121
|
+
*
|
|
122
|
+
* // Handle the followup timer
|
|
123
|
+
* await agent.invoke({
|
|
124
|
+
* triggerName: 'timerFollowup',
|
|
125
|
+
* triggerBody: { message: payload.message },
|
|
126
|
+
* sessionId
|
|
127
|
+
* });
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function onTimer({ timerName, handler }) {
|
|
133
|
+
// Initialize handlers array for this timer name if it doesn't exist
|
|
134
|
+
if (!exports.timerHandlers.has(timerName)) {
|
|
135
|
+
exports.timerHandlers.set(timerName, []);
|
|
136
|
+
}
|
|
137
|
+
// Add the handler to the array for this timer name
|
|
138
|
+
const handlers = exports.timerHandlers.get(timerName);
|
|
139
|
+
handlers.push({ handler });
|
|
140
|
+
}
|
|
141
|
+
mindedConnection.on(mindedConnectionTypes_1.mindedConnectionSocketMessageType.TIMER_TRIGGER, async (timerTriggerMessage) => {
|
|
142
|
+
// Get handlers for the specific timer name
|
|
143
|
+
const handlers = exports.timerHandlers.get(timerTriggerMessage.timerName) || [];
|
|
144
|
+
// Call all handlers registered for this timer name
|
|
145
|
+
for (const { handler } of handlers) {
|
|
146
|
+
await handler({
|
|
147
|
+
sessionId: timerTriggerMessage.sessionId,
|
|
148
|
+
payload: timerTriggerMessage.eventArgs,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/internalTools/timer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,gCAiBC;AAkBD,kCAQC;AA8BD,0BAeC;AA3HD,+EAAiE;AACjE,6EAA+H;AAE/H,qCAAqC;AACxB,QAAA,aAAa,GAAG,IAAI,GAAG,EAE/B,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACI,KAAK,UAAU,UAAU,CAAC,EAC/B,SAAS,EACT,OAAO,EACP,SAAS,EACT,OAAO,GAAG,EAAE,EAMb;IACC,OAAO,MAAM,gBAAgB,CAAC,SAAS,CAAC,yDAAiC,CAAC,WAAW,EAAE;QACrF,SAAS;QACT,OAAO;QACP,SAAS;QACT,SAAS,EAAE,OAAO;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,WAAW,CAAC,SAAiB,EAAE,SAAiB;IACpE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,MAAM,gBAAgB,CAAC,SAAS,CAAC,yDAAiC,CAAC,YAAY,EAAE;QACtF,SAAS;QACT,SAAS;KACV,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,OAAO,CAAC,EACtB,SAAS,EACT,OAAO,EAIR;IACC,oEAAoE;IACpE,IAAI,CAAC,qBAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,qBAAa,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,mDAAmD;IACnD,MAAM,QAAQ,GAAG,qBAAa,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,gBAAgB,CAAC,EAAE,CAAC,yDAAiC,CAAC,aAAa,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE;IACjG,2CAA2C;IAC3C,MAAM,QAAQ,GAAG,qBAAa,CAAC,GAAG,CAAC,mBAAmB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAExE,mDAAmD;IACnD,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,OAAO,CAAC;YACZ,SAAS,EAAE,mBAAmB,CAAC,SAAS;YACxC,OAAO,EAAE,mBAAmB,CAAC,SAAS;SACvC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { BaseCheckpointSaver, CheckpointTuple, Checkpoint, CheckpointMetadata, ChannelVersions, PendingWrite, CheckpointListOptions } from '@langchain/langgraph-checkpoint';
|
|
2
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
|
-
import { MindedConnection } from './mindedConnection';
|
|
4
3
|
export declare class MindedCheckpointSaver extends BaseCheckpointSaver<number> {
|
|
5
|
-
|
|
6
|
-
constructor(mindedConnection: MindedConnection);
|
|
4
|
+
constructor();
|
|
7
5
|
getTuple(config: RunnableConfig<Record<string, any>>): Promise<CheckpointTuple | undefined>;
|
|
8
6
|
list(config: RunnableConfig<Record<string, any>>, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple, any, any>;
|
|
9
7
|
put(config: RunnableConfig<Record<string, any>>, checkpoint: Checkpoint<string, string>, metadata: CheckpointMetadata, newVersions: ChannelVersions): Promise<RunnableConfig<Record<string, any>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mindedCheckpointSaver.d.ts","sourceRoot":"","sources":["../../src/platform/mindedCheckpointSaver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,qBAAqB,EAEtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"mindedCheckpointSaver.d.ts","sourceRoot":"","sources":["../../src/platform/mindedCheckpointSaver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,qBAAqB,EAEtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAchE,qBAAa,qBAAsB,SAAQ,mBAAmB,CAAC,MAAM,CAAC;;IAK9D,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAgD1F,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,cAAc,CAAC,eAAe,EAAE,GAAG,EAAE,GAAG,CAAC;IAgC9H,GAAG,CACP,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3C,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,EACtC,QAAQ,EAAE,kBAAkB,EAC5B,WAAW,EAAE,eAAe,GAC3B,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAmBzC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAYpH"}
|
|
@@ -1,17 +1,50 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.MindedCheckpointSaver = void 0;
|
|
4
37
|
const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
|
|
38
|
+
const mindedConnection = __importStar(require("./mindedConnection"));
|
|
5
39
|
const mindedConnectionTypes_1 = require("./mindedConnectionTypes");
|
|
6
40
|
const logger_1 = require("../utils/logger");
|
|
7
41
|
class MindedCheckpointSaver extends langgraph_checkpoint_1.BaseCheckpointSaver {
|
|
8
|
-
constructor(
|
|
42
|
+
constructor() {
|
|
9
43
|
super();
|
|
10
|
-
this.mindedConnection = mindedConnection;
|
|
11
44
|
}
|
|
12
45
|
async getTuple(config) {
|
|
13
|
-
const response = await
|
|
14
|
-
type: mindedConnectionTypes_1.
|
|
46
|
+
const response = await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_GET_TUPLE, {
|
|
47
|
+
type: mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_GET_TUPLE,
|
|
15
48
|
config,
|
|
16
49
|
});
|
|
17
50
|
if (!response.tuple) {
|
|
@@ -46,8 +79,8 @@ class MindedCheckpointSaver extends langgraph_checkpoint_1.BaseCheckpointSaver {
|
|
|
46
79
|
};
|
|
47
80
|
}
|
|
48
81
|
async *list(config, options) {
|
|
49
|
-
const response = await
|
|
50
|
-
type: mindedConnectionTypes_1.
|
|
82
|
+
const response = await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_LIST, {
|
|
83
|
+
type: mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_LIST,
|
|
51
84
|
config,
|
|
52
85
|
options,
|
|
53
86
|
});
|
|
@@ -72,8 +105,8 @@ class MindedCheckpointSaver extends langgraph_checkpoint_1.BaseCheckpointSaver {
|
|
|
72
105
|
}
|
|
73
106
|
async put(config, checkpoint, metadata, newVersions) {
|
|
74
107
|
try {
|
|
75
|
-
const response = await
|
|
76
|
-
type: mindedConnectionTypes_1.
|
|
108
|
+
const response = await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_PUT, {
|
|
109
|
+
type: mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_PUT,
|
|
77
110
|
config,
|
|
78
111
|
checkpoint,
|
|
79
112
|
metadata,
|
|
@@ -88,8 +121,8 @@ class MindedCheckpointSaver extends langgraph_checkpoint_1.BaseCheckpointSaver {
|
|
|
88
121
|
}
|
|
89
122
|
async putWrites(config, writes, taskId) {
|
|
90
123
|
try {
|
|
91
|
-
await
|
|
92
|
-
type: mindedConnectionTypes_1.
|
|
124
|
+
await mindedConnection.awaitEmit(mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_PUT_WRITES, {
|
|
125
|
+
type: mindedConnectionTypes_1.mindedConnectionSocketMessageType.CHECKPOINT_PUT_WRITES,
|
|
93
126
|
config,
|
|
94
127
|
writes,
|
|
95
128
|
taskId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mindedCheckpointSaver.js","sourceRoot":"","sources":["../../src/platform/mindedCheckpointSaver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mindedCheckpointSaver.js","source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O,KAAK,EAAE,CAAC;YACf,eAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,uBAAuB,EAAE,KAAK,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF;AAzHD,sDAyHC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
1
|
+
import { mindedConnectionSocketMessageType, mindedConnectionSocketMessageTypeMap } from './mindedConnectionTypes';
|
|
2
|
+
export declare const isConnected: () => boolean;
|
|
3
|
+
export declare const on: <E extends keyof mindedConnectionSocketMessageTypeMap>(event: E, callback: (message: mindedConnectionSocketMessageTypeMap[E], callback: (response: any) => void) => void) => void;
|
|
4
|
+
export declare const emit: <E extends keyof mindedConnectionSocketMessageTypeMap>(event: E, message: mindedConnectionSocketMessageTypeMap[E]) => void;
|
|
5
|
+
export declare const awaitEmit: <T, R>(event: mindedConnectionSocketMessageType, message: T, timeoutMs?: number) => Promise<R>;
|
|
6
|
+
export declare const start: () => Promise<void>;
|
|
7
|
+
export declare const disconnect: () => void;
|
|
8
|
+
export declare const mindedConnection: {
|
|
9
|
+
isConnected: () => boolean;
|
|
10
|
+
on: <E extends keyof mindedConnectionSocketMessageTypeMap>(event: E, callback: (message: mindedConnectionSocketMessageTypeMap[E], callback: (response: any) => void) => void) => void;
|
|
11
|
+
emit: <E extends keyof mindedConnectionSocketMessageTypeMap>(event: E, message: mindedConnectionSocketMessageTypeMap[E]) => void;
|
|
12
|
+
awaitEmit: <T, R>(event: mindedConnectionSocketMessageType, message: T, timeoutMs?: number) => Promise<R>;
|
|
13
|
+
start: () => Promise<void>;
|
|
14
|
+
};
|
|
15
15
|
//# sourceMappingURL=mindedConnection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mindedConnection.d.ts","sourceRoot":"","sources":["../../src/platform/mindedConnection.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iCAAiC,EACjC,
|
|
1
|
+
{"version":3,"file":"mindedConnection.d.ts","sourceRoot":"","sources":["../../src/platform/mindedConnection.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iCAAiC,EACjC,oCAAoC,EACrC,MAAM,yBAAyB,CAAC;AAYjC,eAAO,MAAM,WAAW,QAAO,OAE9B,CAAC;AAEF,eAAO,MAAM,EAAE,GAAI,CAAC,SAAS,MAAM,oCAAoC,EACrE,OAAO,CAAC,EACR,UAAU,CAAC,OAAO,EAAE,oCAAoC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,SAMxG,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,oCAAoC,EACvE,OAAO,CAAC,EACR,SAAS,oCAAoC,CAAC,CAAC,CAAC,SAKjD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,CAAC,EAAE,CAAC,EAClC,OAAO,iCAAiC,EACxC,SAAS,CAAC,EACV,YAAW,MAAa,KACvB,OAAO,CAAC,CAAC,CAyBX,CAAC;AAqGF,eAAO,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAM1C,CAAC;AAEF,eAAO,MAAM,UAAU,YAatB,CAAC;AAEF,eAAO,MAAM,gBAAgB;uBAhLE,OAAO;SAInB,CAAC,SAAS,MAAM,oCAAoC,SAC9D,CAAC,YACE,CAAC,OAAO,EAAE,oCAAoC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI;WAQpF,CAAC,SAAS,MAAM,oCAAoC,SAChE,CAAC,WACC,oCAAoC,CAAC,CAAC,CAAC;gBAOlB,CAAC,EAAE,CAAC,SAC3B,iCAAiC,WAC/B,CAAC,cACC,MAAM,KAChB,OAAO,CAAC,CAAC,CAAC;iBA8HkB,OAAO,CAAC,IAAI,CAAC;CA6B3C,CAAC"}
|
|
@@ -1,147 +1,168 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mindedConnection = exports.disconnect = exports.start = exports.awaitEmit = exports.emit = exports.on = exports.isConnected = void 0;
|
|
4
4
|
const socket_io_client_1 = require("socket.io-client");
|
|
5
5
|
const flatted_1 = require("flatted");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
7
|
const logger_1 = require("../utils/logger");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const wait_1 = require("../utils/wait");
|
|
9
|
+
// Module-level singleton state
|
|
10
|
+
let socket = null;
|
|
11
|
+
const listeners = {};
|
|
12
|
+
const isConnected = () => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = socket === null || socket === void 0 ? void 0 : socket.connected) !== null && _a !== void 0 ? _a : false;
|
|
15
|
+
};
|
|
16
|
+
exports.isConnected = isConnected;
|
|
17
|
+
const on = (event, callback) => {
|
|
18
|
+
if (!listeners[event]) {
|
|
19
|
+
listeners[event] = [];
|
|
20
|
+
}
|
|
21
|
+
listeners[event].push(callback);
|
|
22
|
+
};
|
|
23
|
+
exports.on = on;
|
|
24
|
+
const emit = (event, message) => {
|
|
25
|
+
if (socket) {
|
|
26
|
+
socket.emit(event, message);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.emit = emit;
|
|
30
|
+
const awaitEmit = async (event, message, timeoutMs = 5000) => {
|
|
31
|
+
if (!socket) {
|
|
32
|
+
throw new Error('Socket is not connected');
|
|
33
|
+
}
|
|
34
|
+
await waitForConnection();
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
// Set up timeout
|
|
37
|
+
const timeout = setTimeout(() => {
|
|
38
|
+
reject(new Error(`Acknowledgement timeout after ${timeoutMs}ms; event type: ${event}}`));
|
|
39
|
+
}, timeoutMs);
|
|
40
|
+
// Emit with acknowledgement callback
|
|
41
|
+
socket.emit(event, (0, flatted_1.stringify)(message), (response) => {
|
|
42
|
+
clearTimeout(timeout);
|
|
43
|
+
// Check if the response indicates an error
|
|
44
|
+
if (response && response.error) {
|
|
45
|
+
reject(new Error(response.error));
|
|
15
46
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.emit = (event, message) => {
|
|
19
|
-
if (this.socket) {
|
|
20
|
-
this.socket.emit(event, message);
|
|
47
|
+
else {
|
|
48
|
+
resolve(response);
|
|
21
49
|
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.awaitEmit = awaitEmit;
|
|
54
|
+
const waitForConnection = async () => {
|
|
55
|
+
const timeout = 10000;
|
|
56
|
+
const interval = 100;
|
|
57
|
+
let cnt = 0;
|
|
58
|
+
while (!(0, exports.isConnected)()) {
|
|
59
|
+
await (0, wait_1.wait)(interval);
|
|
60
|
+
cnt += interval;
|
|
61
|
+
if (cnt > timeout) {
|
|
62
|
+
throw new Error('Minded connection timeout');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const connect = async (token) => {
|
|
67
|
+
const { isDeployed, baseUrl } = (0, config_1.getConfig)();
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
socket = (0, socket_io_client_1.io)(baseUrl, {
|
|
70
|
+
path: '/minded-connect',
|
|
71
|
+
query: {
|
|
72
|
+
isDeployedAgent: isDeployed,
|
|
73
|
+
token,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
let connected = false;
|
|
77
|
+
let ready = false;
|
|
78
|
+
const checkReady = () => {
|
|
79
|
+
if (connected && ready) {
|
|
80
|
+
logger_1.logger.info('\x1b[32mConnection with Minded platform is ready!\x1b[0m');
|
|
81
|
+
logger_1.logger.info('\x1b[32mPress Ctrl+C to exit...');
|
|
82
|
+
resolve();
|
|
26
83
|
}
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
// Set up timeout
|
|
29
|
-
const timeout = setTimeout(() => {
|
|
30
|
-
reject(new Error(`Acknowledgement timeout after ${timeoutMs}ms; event type: ${event}}`));
|
|
31
|
-
}, timeoutMs);
|
|
32
|
-
// Emit with acknowledgement callback
|
|
33
|
-
this.socket.emit(event, (0, flatted_1.stringify)(message), (response) => {
|
|
34
|
-
clearTimeout(timeout);
|
|
35
|
-
// Check if the response indicates an error
|
|
36
|
-
if (response && response.error) {
|
|
37
|
-
reject(new Error(response.error));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
resolve(response);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
84
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
connected
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
// Listen for ready event from server
|
|
76
|
-
this.socket.on('sdk-socket-ready', (data) => {
|
|
77
|
-
logger_1.logger.info('Server ready signal received', data);
|
|
78
|
-
ready = true;
|
|
79
|
-
checkReady();
|
|
80
|
-
});
|
|
81
|
-
this.socket.on('connect_error', () => {
|
|
82
|
-
logger_1.logger.error('Failed to connect to minded platform');
|
|
83
|
-
reject(new Error('Failed to connect to minded platform'));
|
|
84
|
-
});
|
|
85
|
-
this.socket.on('disconnect', () => {
|
|
86
|
-
logger_1.logger.info('Disconnected from local debugging socket');
|
|
87
|
-
connected = false;
|
|
88
|
-
ready = false;
|
|
89
|
-
});
|
|
90
|
-
// Listen for error messages from the server
|
|
91
|
-
this.socket.on('error', async (error) => {
|
|
92
|
-
var _a;
|
|
93
|
-
logger_1.logger.error({ msg: 'Server error:', error });
|
|
94
|
-
if (error.message.includes('Invalid token')) {
|
|
95
|
-
logger_1.logger.info('Invalid token');
|
|
96
|
-
// Disconnect current socket
|
|
97
|
-
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
98
|
-
this.socket.disconnect();
|
|
99
|
-
}
|
|
100
|
-
// Get new token and reconnect
|
|
101
|
-
await this.connect(token);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
// Listen for specific message types
|
|
105
|
-
this.socket.onAny((event, message, callback) => {
|
|
106
|
-
if (this.listeners[event]) {
|
|
107
|
-
this.listeners[event].forEach((listener) => {
|
|
108
|
-
listener(message, callback);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.warn({ message: 'No listeners found for event', event });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
// Handle process termination
|
|
116
|
-
process.on('SIGINT', () => {
|
|
117
|
-
var _a;
|
|
118
|
-
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
119
|
-
logger_1.logger.info('\nDisconnecting...');
|
|
120
|
-
this.socket.disconnect();
|
|
85
|
+
// Connection event handlers
|
|
86
|
+
socket.on('connect', () => {
|
|
87
|
+
logger_1.logger.info('Socket connected, waiting for server setup...');
|
|
88
|
+
connected = true;
|
|
89
|
+
checkReady();
|
|
90
|
+
});
|
|
91
|
+
// Listen for ready event from server
|
|
92
|
+
socket.on('sdk-socket-ready', (data) => {
|
|
93
|
+
logger_1.logger.info('Server ready signal received', data);
|
|
94
|
+
ready = true;
|
|
95
|
+
checkReady();
|
|
96
|
+
});
|
|
97
|
+
socket.on('connect_error', () => {
|
|
98
|
+
logger_1.logger.error('Failed to connect to minded platform');
|
|
99
|
+
reject(new Error('Failed to connect to minded platform'));
|
|
100
|
+
});
|
|
101
|
+
socket.on('disconnect', () => {
|
|
102
|
+
logger_1.logger.info('Disconnected from local debugging socket');
|
|
103
|
+
connected = false;
|
|
104
|
+
ready = false;
|
|
105
|
+
});
|
|
106
|
+
// Listen for error messages from the server
|
|
107
|
+
socket.on('error', async (error) => {
|
|
108
|
+
logger_1.logger.error({ msg: 'Server error:', error });
|
|
109
|
+
if (error.message.includes('Invalid token')) {
|
|
110
|
+
logger_1.logger.info('Invalid token');
|
|
111
|
+
// Disconnect current socket
|
|
112
|
+
if (socket === null || socket === void 0 ? void 0 : socket.connected) {
|
|
113
|
+
socket.disconnect();
|
|
121
114
|
}
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
// Get new token and reconnect
|
|
116
|
+
await connect(token);
|
|
117
|
+
}
|
|
124
118
|
});
|
|
119
|
+
// Listen for specific message types
|
|
120
|
+
socket.onAny((event, message, callback) => {
|
|
121
|
+
if (listeners[event]) {
|
|
122
|
+
listeners[event].forEach((listener) => {
|
|
123
|
+
listener(message, callback);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.warn({ message: 'No listeners found for event', event });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
// Handle process termination
|
|
131
|
+
process.on('SIGINT', () => {
|
|
132
|
+
if (socket === null || socket === void 0 ? void 0 : socket.connected) {
|
|
133
|
+
logger_1.logger.info('\nDisconnecting...');
|
|
134
|
+
socket.disconnect();
|
|
135
|
+
}
|
|
136
|
+
process.exit(0);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const start = async () => {
|
|
141
|
+
const { token } = (0, config_1.getConfig)();
|
|
142
|
+
if (!token) {
|
|
143
|
+
throw new Error('Minded token not found');
|
|
125
144
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
await connect(token);
|
|
146
|
+
};
|
|
147
|
+
exports.start = start;
|
|
148
|
+
const disconnect = () => {
|
|
149
|
+
if (!socket) {
|
|
150
|
+
logger_1.logger.warn('No socket connection to disconnect');
|
|
151
|
+
return;
|
|
132
152
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
if (this.socket.connected) {
|
|
139
|
-
logger_1.logger.info('Disconnecting from Minded platform...');
|
|
140
|
-
this.socket.disconnect();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
logger_1.logger.warn('Socket is already disconnected');
|
|
153
|
+
if (socket.connected) {
|
|
154
|
+
logger_1.logger.info('Disconnecting from Minded platform...');
|
|
155
|
+
socket.disconnect();
|
|
156
|
+
return;
|
|
144
157
|
}
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
logger_1.logger.warn('Socket is already disconnected');
|
|
159
|
+
};
|
|
160
|
+
exports.disconnect = disconnect;
|
|
161
|
+
exports.mindedConnection = {
|
|
162
|
+
isConnected: exports.isConnected,
|
|
163
|
+
on: exports.on,
|
|
164
|
+
emit: exports.emit,
|
|
165
|
+
awaitEmit: exports.awaitEmit,
|
|
166
|
+
start: exports.start,
|
|
167
|
+
};
|
|
147
168
|
//# sourceMappingURL=mindedConnection.js.map
|