@elizaos/plugin-eliza-classic 2.0.0-alpha.7 → 2.0.11-beta.7
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 +21 -0
- package/README.md +57 -0
- package/package.json +42 -50
- package/dist/actions/generateResponse.d.ts +0 -4
- package/dist/actions/generateResponse.d.ts.map +0 -1
- package/dist/actions/generateResponse.js +0 -50
- package/dist/actions/generateResponse.js.map +0 -1
- package/dist/actions/index.d.ts +0 -2
- package/dist/actions/index.d.ts.map +0 -1
- package/dist/actions/index.js +0 -2
- package/dist/actions/index.js.map +0 -1
- package/dist/browser/index.browser.js +0 -1382
- package/dist/browser/index.browser.js.map +0 -15
- package/dist/build.d.ts +0 -2
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -60
- package/dist/build.js.map +0 -1
- package/dist/cjs/index.node.cjs +0 -1413
- package/dist/cjs/index.node.cjs.map +0 -15
- package/dist/generated/specs/spec-helpers.d.ts +0 -49
- package/dist/generated/specs/spec-helpers.d.ts.map +0 -1
- package/dist/generated/specs/spec-helpers.js +0 -79
- package/dist/generated/specs/spec-helpers.js.map +0 -1
- package/dist/generated/specs/specs.d.ts +0 -73
- package/dist/generated/specs/specs.d.ts.map +0 -1
- package/dist/generated/specs/specs.js +0 -61
- package/dist/generated/specs/specs.js.map +0 -1
- package/dist/index.browser.d.ts +0 -2
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -2
- package/dist/index.browser.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/index.node.d.ts +0 -2
- package/dist/index.node.d.ts.map +0 -1
- package/dist/index.node.js +0 -2
- package/dist/index.node.js.map +0 -1
- package/dist/models/index.d.ts +0 -2
- package/dist/models/index.d.ts.map +0 -1
- package/dist/models/index.js +0 -2
- package/dist/models/index.js.map +0 -1
- package/dist/models/text.d.ts +0 -8
- package/dist/models/text.d.ts.map +0 -1
- package/dist/models/text.js +0 -425
- package/dist/models/text.js.map +0 -1
- package/dist/node/index.node.js +0 -1382
- package/dist/node/index.node.js.map +0 -15
- package/dist/plugin.d.ts +0 -4
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -91
- package/dist/plugin.js.map +0 -1
- package/dist/providers/elizaGreeting.d.ts +0 -4
- package/dist/providers/elizaGreeting.d.ts.map +0 -1
- package/dist/providers/elizaGreeting.js +0 -21
- package/dist/providers/elizaGreeting.js.map +0 -1
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -2
- package/dist/providers/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -49
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
package/dist/cjs/index.node.cjs
DELETED
|
@@ -1,1413 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// index.node.ts
|
|
30
|
-
var exports_index_node = {};
|
|
31
|
-
__export(exports_index_node, {
|
|
32
|
-
handleTextSmall: () => handleTextSmall,
|
|
33
|
-
handleTextLarge: () => handleTextLarge,
|
|
34
|
-
getElizaGreeting: () => getElizaGreeting,
|
|
35
|
-
generateElizaResponse: () => generateElizaResponse,
|
|
36
|
-
elizaClassicPlugin: () => elizaClassicPlugin
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(exports_index_node);
|
|
39
|
-
// ../shared/doctor.json
|
|
40
|
-
var doctor_default = {
|
|
41
|
-
greetings: [
|
|
42
|
-
"Hello, how are you feeling today?",
|
|
43
|
-
"How do you do? Please tell me your problem"
|
|
44
|
-
],
|
|
45
|
-
goodbyes: [
|
|
46
|
-
"Goodbye",
|
|
47
|
-
"Till next time",
|
|
48
|
-
"Hope to see you again soon"
|
|
49
|
-
],
|
|
50
|
-
default: [
|
|
51
|
-
"I am not sure I understand you fully",
|
|
52
|
-
"Please go on",
|
|
53
|
-
"What does that suggest to you?",
|
|
54
|
-
"Do you feel strongly about discussing such things?"
|
|
55
|
-
],
|
|
56
|
-
reflections: {
|
|
57
|
-
dont: "don't",
|
|
58
|
-
cant: "can't",
|
|
59
|
-
wont: "won't",
|
|
60
|
-
i: "you",
|
|
61
|
-
am: "are",
|
|
62
|
-
were: "was",
|
|
63
|
-
dreamed: "dreamt",
|
|
64
|
-
dreams: "dream",
|
|
65
|
-
your: "my",
|
|
66
|
-
me: "you",
|
|
67
|
-
"you're": "I am",
|
|
68
|
-
myself: "yourself",
|
|
69
|
-
yourself: "myself",
|
|
70
|
-
mom: "mother",
|
|
71
|
-
dad: "father",
|
|
72
|
-
my: "your",
|
|
73
|
-
you: "I"
|
|
74
|
-
},
|
|
75
|
-
substitutions: {
|
|
76
|
-
dont: "don't",
|
|
77
|
-
cant: "can't",
|
|
78
|
-
wont: "won't",
|
|
79
|
-
dreamed: "dreamt",
|
|
80
|
-
dreams: "dream",
|
|
81
|
-
were: "was",
|
|
82
|
-
mom: "mother",
|
|
83
|
-
dad: "father",
|
|
84
|
-
"you're": "i'm",
|
|
85
|
-
"i'm": "you're",
|
|
86
|
-
am: "are",
|
|
87
|
-
are: "am",
|
|
88
|
-
my: "your",
|
|
89
|
-
your: "my",
|
|
90
|
-
me: "you",
|
|
91
|
-
you: "i",
|
|
92
|
-
myself: "yourself",
|
|
93
|
-
yourself: "myself"
|
|
94
|
-
},
|
|
95
|
-
groups: {
|
|
96
|
-
belief: [
|
|
97
|
-
"feel",
|
|
98
|
-
"think",
|
|
99
|
-
"believe",
|
|
100
|
-
"wish"
|
|
101
|
-
],
|
|
102
|
-
family: [
|
|
103
|
-
"mother",
|
|
104
|
-
"father",
|
|
105
|
-
"sister",
|
|
106
|
-
"brother",
|
|
107
|
-
"wife",
|
|
108
|
-
"children"
|
|
109
|
-
],
|
|
110
|
-
noun: [
|
|
111
|
-
"mother",
|
|
112
|
-
"father"
|
|
113
|
-
]
|
|
114
|
-
},
|
|
115
|
-
keywords: [
|
|
116
|
-
{
|
|
117
|
-
keyword: ["sorry"],
|
|
118
|
-
precedence: 0,
|
|
119
|
-
rules: [
|
|
120
|
-
{
|
|
121
|
-
decomposition: "*",
|
|
122
|
-
reassembly: [
|
|
123
|
-
"Please don't apologize",
|
|
124
|
-
"Apologies are not necessary",
|
|
125
|
-
"What feelings do you have when you apologize?",
|
|
126
|
-
"I've told you that apologies are not required"
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
keyword: ["remember"],
|
|
133
|
-
precedence: 5,
|
|
134
|
-
rules: [
|
|
135
|
-
{
|
|
136
|
-
decomposition: "* you remember *",
|
|
137
|
-
reassembly: [
|
|
138
|
-
"Do you often think of $4?",
|
|
139
|
-
"Does thinking of $4 bring anything else to mind?",
|
|
140
|
-
"What else do you remember?",
|
|
141
|
-
"Why do you remember $4 just now?",
|
|
142
|
-
"What in the present situation reminds you of $4?",
|
|
143
|
-
"What is the connection between me and $4?"
|
|
144
|
-
]
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
decomposition: "* do i remember *",
|
|
148
|
-
reassembly: [
|
|
149
|
-
"Did you think I would forget $5?",
|
|
150
|
-
"Why do you think I should recall $5 now?",
|
|
151
|
-
"What about $5?",
|
|
152
|
-
"=what",
|
|
153
|
-
"You mentioned $5"
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
decomposition: "*",
|
|
158
|
-
reassembly: [
|
|
159
|
-
":newkey"
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
]
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
keyword: ["if"],
|
|
166
|
-
precedence: 3,
|
|
167
|
-
rules: [
|
|
168
|
-
{
|
|
169
|
-
decomposition: "* if *",
|
|
170
|
-
reassembly: [
|
|
171
|
-
"Do you think it's likely that $3?",
|
|
172
|
-
"Do you wish that $3?",
|
|
173
|
-
"What do you think about $3?",
|
|
174
|
-
"Really, $2 $3?"
|
|
175
|
-
]
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
keyword: ["dreamt", "dreamed"],
|
|
181
|
-
precedence: 4,
|
|
182
|
-
rules: [
|
|
183
|
-
{
|
|
184
|
-
decomposition: "* you dreamt *",
|
|
185
|
-
reassembly: [
|
|
186
|
-
"Really, $4?",
|
|
187
|
-
"Have you ever fantasied $4 while you were awake?",
|
|
188
|
-
"Have you dreamt $4 before?",
|
|
189
|
-
"=dream",
|
|
190
|
-
":newkey"
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
]
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
keyword: ["dream", "dreams"],
|
|
197
|
-
precedence: 3,
|
|
198
|
-
rules: [
|
|
199
|
-
{
|
|
200
|
-
decomposition: "*",
|
|
201
|
-
reassembly: [
|
|
202
|
-
"What does that dream suggest to you?",
|
|
203
|
-
"Do you dream often?",
|
|
204
|
-
"What people appear in your dreams?",
|
|
205
|
-
"Don't you believe that dream has something to do with your problem?",
|
|
206
|
-
":newkey"
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
keyword: ["perhaps", "maybe"],
|
|
213
|
-
precedence: 0,
|
|
214
|
-
rules: [
|
|
215
|
-
{
|
|
216
|
-
decomposition: "*",
|
|
217
|
-
reassembly: [
|
|
218
|
-
"You don't seem quite certain",
|
|
219
|
-
"Why the uncertain tone?",
|
|
220
|
-
"Can't you be more positive?",
|
|
221
|
-
"You aren't sure...",
|
|
222
|
-
"Don't you know?"
|
|
223
|
-
]
|
|
224
|
-
}
|
|
225
|
-
]
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
keyword: ["name"],
|
|
229
|
-
precedence: 15,
|
|
230
|
-
rules: [
|
|
231
|
-
{
|
|
232
|
-
decomposition: "*",
|
|
233
|
-
reassembly: [
|
|
234
|
-
"I am not interested in names",
|
|
235
|
-
"I've told you before, I don't care about names --- Please continue"
|
|
236
|
-
]
|
|
237
|
-
}
|
|
238
|
-
]
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
keyword: ["xfremd", "deutsch", "français", "italiano", "español"],
|
|
242
|
-
precedence: 0,
|
|
243
|
-
rules: [
|
|
244
|
-
{
|
|
245
|
-
decomposition: "*",
|
|
246
|
-
reassembly: [
|
|
247
|
-
"I am sorry, I speak only English"
|
|
248
|
-
]
|
|
249
|
-
}
|
|
250
|
-
]
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
keyword: ["hello"],
|
|
254
|
-
precedence: 0,
|
|
255
|
-
rules: [
|
|
256
|
-
{
|
|
257
|
-
decomposition: "*",
|
|
258
|
-
reassembly: [
|
|
259
|
-
"How do you do? Please state your problem"
|
|
260
|
-
]
|
|
261
|
-
}
|
|
262
|
-
]
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
keyword: ["computer", "machine", "machines", "computers"],
|
|
266
|
-
precedence: 50,
|
|
267
|
-
rules: [
|
|
268
|
-
{
|
|
269
|
-
decomposition: "*",
|
|
270
|
-
reassembly: [
|
|
271
|
-
"Do computers worry you?",
|
|
272
|
-
"Why do you mention computers?",
|
|
273
|
-
"What do you think machines have to do with your problem?",
|
|
274
|
-
"Don't you think computers can help people?",
|
|
275
|
-
"What about machines worries you?",
|
|
276
|
-
"What do you think about machines?"
|
|
277
|
-
]
|
|
278
|
-
}
|
|
279
|
-
]
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
keyword: ["am"],
|
|
283
|
-
precedence: 0,
|
|
284
|
-
rules: [
|
|
285
|
-
{
|
|
286
|
-
decomposition: "* are you *",
|
|
287
|
-
reassembly: [
|
|
288
|
-
"Do you believe you are $4?",
|
|
289
|
-
"Would you want to be $4?",
|
|
290
|
-
"You wish I would tell you you are $4",
|
|
291
|
-
"What would it mean if you were $4?",
|
|
292
|
-
"=what"
|
|
293
|
-
]
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
decomposition: "*",
|
|
297
|
-
reassembly: [
|
|
298
|
-
"Why do you say 'am'?",
|
|
299
|
-
"I don't understand that"
|
|
300
|
-
]
|
|
301
|
-
}
|
|
302
|
-
]
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
keyword: ["are"],
|
|
306
|
-
precedence: 0,
|
|
307
|
-
rules: [
|
|
308
|
-
{
|
|
309
|
-
decomposition: "* are i *",
|
|
310
|
-
reassembly: [
|
|
311
|
-
"Why are you interested in whether I am $4 or not?",
|
|
312
|
-
"Would you prefer if I weren't $4?",
|
|
313
|
-
"Perhaps I am $4 in your fantasies",
|
|
314
|
-
"Do you sometimes think I am $4?",
|
|
315
|
-
"=what"
|
|
316
|
-
]
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
decomposition: "* are *",
|
|
320
|
-
reassembly: [
|
|
321
|
-
"Did you think they might not be $3?",
|
|
322
|
-
"Would you like it if they were not $3?",
|
|
323
|
-
"What if they were not $3?",
|
|
324
|
-
"Possibly they are $3"
|
|
325
|
-
]
|
|
326
|
-
}
|
|
327
|
-
]
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
keyword: ["your"],
|
|
331
|
-
precedence: 0,
|
|
332
|
-
rules: [
|
|
333
|
-
{
|
|
334
|
-
decomposition: "* my *",
|
|
335
|
-
reassembly: [
|
|
336
|
-
"Why are you concerned over my $3?",
|
|
337
|
-
"What about your own $3?",
|
|
338
|
-
"Are you worried about someone else's $3?",
|
|
339
|
-
"Really, my $3?"
|
|
340
|
-
]
|
|
341
|
-
}
|
|
342
|
-
]
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
keyword: ["was", "were"],
|
|
346
|
-
precedence: 2,
|
|
347
|
-
rules: [
|
|
348
|
-
{
|
|
349
|
-
decomposition: "* was you *",
|
|
350
|
-
reassembly: [
|
|
351
|
-
"What if you were $4?",
|
|
352
|
-
"Do you think you were $4?",
|
|
353
|
-
"Were you $4?",
|
|
354
|
-
"What would it mean if you were $4?",
|
|
355
|
-
"What does '$4' suggest to you?",
|
|
356
|
-
"=what"
|
|
357
|
-
]
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
decomposition: "* you was *",
|
|
361
|
-
reassembly: [
|
|
362
|
-
"Were you really?",
|
|
363
|
-
"Why do you tell me you were $4 now?",
|
|
364
|
-
"Perhaps I already knew you were $4"
|
|
365
|
-
]
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
decomposition: "* was i *",
|
|
369
|
-
reassembly: [
|
|
370
|
-
"Would you like to believe I was $4?",
|
|
371
|
-
"What suggests that I was $4?",
|
|
372
|
-
"What do you think?",
|
|
373
|
-
"Perhaps I was $4",
|
|
374
|
-
"What if I had been $4?"
|
|
375
|
-
]
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
decomposition: "*",
|
|
379
|
-
reassembly: [
|
|
380
|
-
":newkey"
|
|
381
|
-
]
|
|
382
|
-
}
|
|
383
|
-
]
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
keyword: ["you're"],
|
|
387
|
-
precedence: 0,
|
|
388
|
-
rules: [
|
|
389
|
-
{
|
|
390
|
-
decomposition: "* i'm *",
|
|
391
|
-
reassembly: [
|
|
392
|
-
":pre I ARE $3 (=you)"
|
|
393
|
-
]
|
|
394
|
-
}
|
|
395
|
-
]
|
|
396
|
-
},
|
|
397
|
-
{
|
|
398
|
-
keyword: ["i'm"],
|
|
399
|
-
precedence: 0,
|
|
400
|
-
rules: [
|
|
401
|
-
{
|
|
402
|
-
decomposition: "* you're *",
|
|
403
|
-
reassembly: [
|
|
404
|
-
":pre YOU ARE $3 (=i)"
|
|
405
|
-
]
|
|
406
|
-
}
|
|
407
|
-
]
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
keyword: ["i"],
|
|
411
|
-
precedence: 0,
|
|
412
|
-
rules: [
|
|
413
|
-
{
|
|
414
|
-
decomposition: "* you [want need] *",
|
|
415
|
-
reassembly: [
|
|
416
|
-
"What would it mean to you if you got $4?",
|
|
417
|
-
"Why do you want $4?",
|
|
418
|
-
"Suppose you got $4 soon",
|
|
419
|
-
"What if you never got $4",
|
|
420
|
-
"What would getting $4 mean to you?",
|
|
421
|
-
"What does wanting $4 have to do with this discussion?"
|
|
422
|
-
]
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
decomposition: "* you are * [sad unhappy depressed sick] *",
|
|
426
|
-
reassembly: [
|
|
427
|
-
"I am sorry to hear you are $5",
|
|
428
|
-
"Do you think coming here will help you not to be $5?",
|
|
429
|
-
"I'm sure its not pleasant to be $5",
|
|
430
|
-
"Can you explain what made you $5"
|
|
431
|
-
]
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
decomposition: "* you are * [happy elated glad better] *",
|
|
435
|
-
reassembly: [
|
|
436
|
-
"How have I helped you to be $5?",
|
|
437
|
-
"Has your treatment made you $5?",
|
|
438
|
-
"What makes you $5 just now?",
|
|
439
|
-
"Can you explain why you are suddenly $5?"
|
|
440
|
-
]
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
decomposition: "* you was *",
|
|
444
|
-
reassembly: [
|
|
445
|
-
"=was"
|
|
446
|
-
]
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
decomposition: "* you @belief you *",
|
|
450
|
-
reassembly: [
|
|
451
|
-
"Do you really think so?",
|
|
452
|
-
"But you are not sure you $5",
|
|
453
|
-
"Do you really doubt you $5?"
|
|
454
|
-
]
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
decomposition: "* you * @belief * I *",
|
|
458
|
-
reassembly: [
|
|
459
|
-
"=you"
|
|
460
|
-
]
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
decomposition: "* you are *",
|
|
464
|
-
reassembly: [
|
|
465
|
-
"Is it because you are $4 that you came to me?",
|
|
466
|
-
"How long have you been $4?",
|
|
467
|
-
"Do you believe it normal to be $4?",
|
|
468
|
-
"Do you enjoy being $4?"
|
|
469
|
-
]
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
decomposition: "* you [can't cannot] *",
|
|
473
|
-
reassembly: [
|
|
474
|
-
"How do you know you can't $4?",
|
|
475
|
-
"Have you tried?",
|
|
476
|
-
"Perhaps you could $4 now",
|
|
477
|
-
"Do you really want to be able to $4?"
|
|
478
|
-
]
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
decomposition: "* you don't *",
|
|
482
|
-
reassembly: [
|
|
483
|
-
"Don't you really $4?",
|
|
484
|
-
"Why don't you $4?",
|
|
485
|
-
"Do you wish to be able to $4?",
|
|
486
|
-
"Does that trouble you?"
|
|
487
|
-
]
|
|
488
|
-
},
|
|
489
|
-
{
|
|
490
|
-
decomposition: "* you feel *",
|
|
491
|
-
reassembly: [
|
|
492
|
-
"Tell me more about such feelings",
|
|
493
|
-
"Do you often feel $4?",
|
|
494
|
-
"Do you enjoy feeling $4?",
|
|
495
|
-
"Of what does feeling $4 remind you?"
|
|
496
|
-
]
|
|
497
|
-
},
|
|
498
|
-
{
|
|
499
|
-
decomposition: "* you * i *",
|
|
500
|
-
reassembly: [
|
|
501
|
-
"Perhaps in your fantasy we $3 each other",
|
|
502
|
-
"Do you wish to $3 me?",
|
|
503
|
-
"You seem to need to $3 me",
|
|
504
|
-
"Do you $3 anyone else?"
|
|
505
|
-
]
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
decomposition: "*",
|
|
509
|
-
reassembly: [
|
|
510
|
-
"You say $1",
|
|
511
|
-
"Can you elaborate on that?",
|
|
512
|
-
"Do you say $1 for some special reason?",
|
|
513
|
-
"That's quite interesting"
|
|
514
|
-
]
|
|
515
|
-
}
|
|
516
|
-
]
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
keyword: ["you"],
|
|
520
|
-
precedence: 0,
|
|
521
|
-
rules: [
|
|
522
|
-
{
|
|
523
|
-
decomposition: "* i remind you of *",
|
|
524
|
-
reassembly: [
|
|
525
|
-
"=dit"
|
|
526
|
-
]
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
decomposition: "* i are *",
|
|
530
|
-
reassembly: [
|
|
531
|
-
"What makes you think I am $4?",
|
|
532
|
-
"Does it please you to believe I am $4?",
|
|
533
|
-
"Do you sometimes wish you were $4?",
|
|
534
|
-
"Perhaps you would like to be $4"
|
|
535
|
-
]
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
decomposition: "* i * you",
|
|
539
|
-
reassembly: [
|
|
540
|
-
"Why do you think I $3 you?",
|
|
541
|
-
"You like to think I $3 you --- don't you",
|
|
542
|
-
"What makes you think I $3 you?",
|
|
543
|
-
"Really, I $3 you?",
|
|
544
|
-
"Do you wish to believe I $3 you?",
|
|
545
|
-
"Suppose I did $3 to you --- What would that mean?",
|
|
546
|
-
"Does someone else believe I $3 you?"
|
|
547
|
-
]
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
decomposition: "* i *",
|
|
551
|
-
reassembly: [
|
|
552
|
-
"We were discussing you --- not me",
|
|
553
|
-
"Oh, I $3",
|
|
554
|
-
"You're not really talking about me, are you?",
|
|
555
|
-
"What are your feelings now?"
|
|
556
|
-
]
|
|
557
|
-
}
|
|
558
|
-
]
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
keyword: ["yes", "certainly"],
|
|
562
|
-
precedence: 0,
|
|
563
|
-
rules: [
|
|
564
|
-
{
|
|
565
|
-
decomposition: "*",
|
|
566
|
-
reassembly: [
|
|
567
|
-
"You seem quite positive",
|
|
568
|
-
"You are sure",
|
|
569
|
-
"I see",
|
|
570
|
-
"I understand"
|
|
571
|
-
]
|
|
572
|
-
}
|
|
573
|
-
]
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
keyword: ["no"],
|
|
577
|
-
precedence: 0,
|
|
578
|
-
rules: [
|
|
579
|
-
{
|
|
580
|
-
decomposition: "*",
|
|
581
|
-
reassembly: [
|
|
582
|
-
"Are you saying 'no' just to be negative?",
|
|
583
|
-
"You are being a bit negative",
|
|
584
|
-
"Why not?",
|
|
585
|
-
"why 'no'?"
|
|
586
|
-
]
|
|
587
|
-
}
|
|
588
|
-
]
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
keyword: ["my"],
|
|
592
|
-
precedence: 2,
|
|
593
|
-
rules: [
|
|
594
|
-
{
|
|
595
|
-
decomposition: "* your * @family *",
|
|
596
|
-
reassembly: [
|
|
597
|
-
"Tell me more about your family",
|
|
598
|
-
"Who else in your family $5?",
|
|
599
|
-
"Your $4",
|
|
600
|
-
"What else comes to mind when you think of your $4?"
|
|
601
|
-
]
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
decomposition: "* your *",
|
|
605
|
-
reassembly: [
|
|
606
|
-
"Your $3",
|
|
607
|
-
"Why do you say your $3?",
|
|
608
|
-
"Does that suggest anything else which belongs to you?",
|
|
609
|
-
"Is it important to you that $1 your $3?"
|
|
610
|
-
]
|
|
611
|
-
}
|
|
612
|
-
],
|
|
613
|
-
memory: [
|
|
614
|
-
{
|
|
615
|
-
decomposition: "* your *",
|
|
616
|
-
reassembly: [
|
|
617
|
-
"Let's discuss further why your $3",
|
|
618
|
-
"Earlier you said your $3",
|
|
619
|
-
"But your $3",
|
|
620
|
-
"Does that have anything to do with the fact that your $3?"
|
|
621
|
-
]
|
|
622
|
-
}
|
|
623
|
-
]
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
keyword: ["can"],
|
|
627
|
-
precedence: 0,
|
|
628
|
-
rules: [
|
|
629
|
-
{
|
|
630
|
-
decomposition: "* can i *",
|
|
631
|
-
reassembly: [
|
|
632
|
-
"You believe I can $4 don't you?",
|
|
633
|
-
"=what",
|
|
634
|
-
"You want me to be able to $4",
|
|
635
|
-
"Perhaps you would like to be able to $4 yourself"
|
|
636
|
-
]
|
|
637
|
-
},
|
|
638
|
-
{
|
|
639
|
-
decomposition: "* can you *",
|
|
640
|
-
reassembly: [
|
|
641
|
-
"Whether or not you can $4 depends on you more than me",
|
|
642
|
-
"Do you want to be able to $4?",
|
|
643
|
-
"Perhaps you don't want to $4",
|
|
644
|
-
"=what"
|
|
645
|
-
]
|
|
646
|
-
}
|
|
647
|
-
]
|
|
648
|
-
},
|
|
649
|
-
{
|
|
650
|
-
keyword: ["what", "how", "when"],
|
|
651
|
-
precedence: 0,
|
|
652
|
-
rules: [
|
|
653
|
-
{
|
|
654
|
-
decomposition: "*",
|
|
655
|
-
reassembly: [
|
|
656
|
-
"Why do you ask?",
|
|
657
|
-
"Does that question interest you?",
|
|
658
|
-
"What is it you really want to know?",
|
|
659
|
-
"Are such questions much on your mind?",
|
|
660
|
-
"What answer would please you most?",
|
|
661
|
-
"What do you think?",
|
|
662
|
-
"What comes to your mind when you ask that?",
|
|
663
|
-
"Have you asked such question before?",
|
|
664
|
-
"Have you asked anyone else?"
|
|
665
|
-
]
|
|
666
|
-
}
|
|
667
|
-
]
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
keyword: ["because"],
|
|
671
|
-
precedence: 0,
|
|
672
|
-
rules: [
|
|
673
|
-
{
|
|
674
|
-
decomposition: "*",
|
|
675
|
-
reassembly: [
|
|
676
|
-
"Is that the real reason?",
|
|
677
|
-
"Don't any other reasons come to mind?",
|
|
678
|
-
"Does that reason seem to explain anything else?",
|
|
679
|
-
"What other reasons might there be?"
|
|
680
|
-
]
|
|
681
|
-
}
|
|
682
|
-
]
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
keyword: ["why"],
|
|
686
|
-
precedence: 0,
|
|
687
|
-
rules: [
|
|
688
|
-
{
|
|
689
|
-
decomposition: "* why don't i *",
|
|
690
|
-
reassembly: [
|
|
691
|
-
"Do you believe I don't $5?",
|
|
692
|
-
"Perhaps I will $5 in good time",
|
|
693
|
-
"Should you $5 yourself?",
|
|
694
|
-
"You want me to $5",
|
|
695
|
-
"=what"
|
|
696
|
-
]
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
decomposition: "* why can't you *",
|
|
700
|
-
reassembly: [
|
|
701
|
-
"Do you think you should be able to $5?",
|
|
702
|
-
"Do you want to be able to $5?",
|
|
703
|
-
"Do you believe this will help you to $5?",
|
|
704
|
-
"Have you any idea why you can't $5?",
|
|
705
|
-
"=what"
|
|
706
|
-
]
|
|
707
|
-
}
|
|
708
|
-
]
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
keyword: ["everyone", "everybody", "nobody", "noone"],
|
|
712
|
-
precedence: 2,
|
|
713
|
-
rules: [
|
|
714
|
-
{
|
|
715
|
-
decomposition: "* [everyone everybody nobody noone] *",
|
|
716
|
-
reassembly: [
|
|
717
|
-
"Really, $2?",
|
|
718
|
-
"Surely not $2",
|
|
719
|
-
"Can you think of anyone in particular?",
|
|
720
|
-
"Who, for example?",
|
|
721
|
-
"You are thinking of a very special person",
|
|
722
|
-
"Who, may I ask?",
|
|
723
|
-
"Someone special perhaps",
|
|
724
|
-
"You have a particular person in mind, don't you?",
|
|
725
|
-
"Who do you think you're talking about?"
|
|
726
|
-
]
|
|
727
|
-
}
|
|
728
|
-
]
|
|
729
|
-
},
|
|
730
|
-
{
|
|
731
|
-
keyword: ["always"],
|
|
732
|
-
precedence: 1,
|
|
733
|
-
rules: [
|
|
734
|
-
{
|
|
735
|
-
decomposition: "*",
|
|
736
|
-
reassembly: [
|
|
737
|
-
"Can you think of a specific example?",
|
|
738
|
-
"When?",
|
|
739
|
-
"What incident are you thinking of?",
|
|
740
|
-
"Really, always?"
|
|
741
|
-
]
|
|
742
|
-
}
|
|
743
|
-
]
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
keyword: ["like"],
|
|
747
|
-
precedence: 10,
|
|
748
|
-
rules: [
|
|
749
|
-
{
|
|
750
|
-
decomposition: "* [am is are was] * like *",
|
|
751
|
-
reassembly: [
|
|
752
|
-
"=dit"
|
|
753
|
-
]
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
decomposition: "*",
|
|
757
|
-
reassembly: [
|
|
758
|
-
":newkey"
|
|
759
|
-
]
|
|
760
|
-
}
|
|
761
|
-
]
|
|
762
|
-
},
|
|
763
|
-
{
|
|
764
|
-
keyword: ["alike", "same"],
|
|
765
|
-
precedence: 10,
|
|
766
|
-
rules: [
|
|
767
|
-
{
|
|
768
|
-
decomposition: "*",
|
|
769
|
-
reassembly: [
|
|
770
|
-
"=dit"
|
|
771
|
-
]
|
|
772
|
-
}
|
|
773
|
-
]
|
|
774
|
-
},
|
|
775
|
-
{
|
|
776
|
-
keyword: ["dit"],
|
|
777
|
-
precedence: 0,
|
|
778
|
-
rules: [
|
|
779
|
-
{
|
|
780
|
-
decomposition: "*",
|
|
781
|
-
reassembly: [
|
|
782
|
-
"In what way?",
|
|
783
|
-
"What resemblance do you see?",
|
|
784
|
-
"What does that similarity suggest to you?",
|
|
785
|
-
"What other connections do you see?",
|
|
786
|
-
"What do you suppose that resemblance means?",
|
|
787
|
-
"What is the connection, do you suppose?",
|
|
788
|
-
"Could there really be some connection?",
|
|
789
|
-
"How?"
|
|
790
|
-
]
|
|
791
|
-
}
|
|
792
|
-
]
|
|
793
|
-
}
|
|
794
|
-
]
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
// models/text.ts
|
|
798
|
-
var script = doctor_default;
|
|
799
|
-
var substitutions = script.substitutions ?? {};
|
|
800
|
-
var sessionStateByRuntime = new WeakMap;
|
|
801
|
-
var defaultStandaloneSession = {
|
|
802
|
-
limit: 1,
|
|
803
|
-
memories: [],
|
|
804
|
-
reassemblyIndex: new Map
|
|
805
|
-
};
|
|
806
|
-
function getOrCreateSession(runtime) {
|
|
807
|
-
const existing = sessionStateByRuntime.get(runtime);
|
|
808
|
-
if (existing)
|
|
809
|
-
return existing;
|
|
810
|
-
const created = {
|
|
811
|
-
limit: 1,
|
|
812
|
-
memories: [],
|
|
813
|
-
reassemblyIndex: new Map
|
|
814
|
-
};
|
|
815
|
-
sessionStateByRuntime.set(runtime, created);
|
|
816
|
-
return created;
|
|
817
|
-
}
|
|
818
|
-
function normalizeRawInput(input) {
|
|
819
|
-
return input.trim().replace(/[!?;:]+/g, " ").replace(/[\u2018\u2019]/g, "'").replace(/\s+/g, " ");
|
|
820
|
-
}
|
|
821
|
-
function tokenizeWords(text) {
|
|
822
|
-
const cleaned = normalizeRawInput(text).replace(/[.,"()]/g, " ").toLowerCase().replace(/\s+/g, " ").trim();
|
|
823
|
-
if (!cleaned)
|
|
824
|
-
return [];
|
|
825
|
-
const canonicalizationKeys = new Set(["dont", "cant", "wont", "dreamed", "dreams", "mom", "dad"]);
|
|
826
|
-
return cleaned.split(" ").filter((w) => w.length > 0).map((w) => canonicalizationKeys.has(w) ? substitutions[w] ?? script.reflections[w] ?? w : w);
|
|
827
|
-
}
|
|
828
|
-
function reflectWords(words) {
|
|
829
|
-
return words.map((w) => script.reflections[w] ?? w);
|
|
830
|
-
}
|
|
831
|
-
function reflectText(text) {
|
|
832
|
-
return reflectWords(tokenizeWords(text)).join(" ");
|
|
833
|
-
}
|
|
834
|
-
function substituteWordsForMatching(words) {
|
|
835
|
-
const out = [];
|
|
836
|
-
for (const w of words) {
|
|
837
|
-
const mapped = substitutions[w] ?? script.reflections[w];
|
|
838
|
-
if (!mapped) {
|
|
839
|
-
out.push(w.toLowerCase());
|
|
840
|
-
continue;
|
|
841
|
-
}
|
|
842
|
-
const parts = mapped.toLowerCase().split(/\s+/g).filter((p) => p.length > 0);
|
|
843
|
-
if (parts.length === 0)
|
|
844
|
-
out.push(w.toLowerCase());
|
|
845
|
-
else
|
|
846
|
-
out.push(...parts);
|
|
847
|
-
}
|
|
848
|
-
return out;
|
|
849
|
-
}
|
|
850
|
-
function tokenizeForScan(input) {
|
|
851
|
-
const cleaned = normalizeRawInput(input).replace(/[.,]/g, " | ").replace(/["()]/g, " ").toLowerCase().replace(/\s+/g, " ").trim();
|
|
852
|
-
if (!cleaned)
|
|
853
|
-
return [];
|
|
854
|
-
const canonicalizationKeys = new Set(["dont", "cant", "wont", "dreamed", "dreams", "mom", "dad"]);
|
|
855
|
-
return cleaned.split(" ").filter((w) => w.length > 0).map((w) => canonicalizationKeys.has(w) ? substitutions[w] ?? script.reflections[w] ?? w : w);
|
|
856
|
-
}
|
|
857
|
-
function splitIntoClauses(words) {
|
|
858
|
-
const clauses = [];
|
|
859
|
-
let current = [];
|
|
860
|
-
for (const w of words) {
|
|
861
|
-
if (w === "|" || w === "but") {
|
|
862
|
-
if (current.length > 0)
|
|
863
|
-
clauses.push(current);
|
|
864
|
-
current = [];
|
|
865
|
-
continue;
|
|
866
|
-
}
|
|
867
|
-
current.push(w);
|
|
868
|
-
}
|
|
869
|
-
if (current.length > 0)
|
|
870
|
-
clauses.push(current);
|
|
871
|
-
return clauses;
|
|
872
|
-
}
|
|
873
|
-
function buildKeywordIndex(keywords) {
|
|
874
|
-
const map = new Map;
|
|
875
|
-
for (const entry of keywords) {
|
|
876
|
-
for (const k of entry.keyword) {
|
|
877
|
-
map.set(k.toLowerCase(), entry);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return map;
|
|
881
|
-
}
|
|
882
|
-
var keywordIndex = buildKeywordIndex(script.keywords);
|
|
883
|
-
function findKeywordsInClause(words) {
|
|
884
|
-
const found = [];
|
|
885
|
-
for (let i = 0;i < words.length; i++) {
|
|
886
|
-
const w = words[i];
|
|
887
|
-
const entry = keywordIndex.get(w);
|
|
888
|
-
if (!entry)
|
|
889
|
-
continue;
|
|
890
|
-
found.push({ entry, keyword: w, position: i });
|
|
891
|
-
}
|
|
892
|
-
return found;
|
|
893
|
-
}
|
|
894
|
-
function selectKeywordStack(words) {
|
|
895
|
-
const clauses = splitIntoClauses(words);
|
|
896
|
-
for (const clause of clauses) {
|
|
897
|
-
const found = findKeywordsInClause(clause);
|
|
898
|
-
if (found.length === 0)
|
|
899
|
-
continue;
|
|
900
|
-
const stack = [...found].sort((a, b) => {
|
|
901
|
-
if (b.entry.precedence !== a.entry.precedence)
|
|
902
|
-
return b.entry.precedence - a.entry.precedence;
|
|
903
|
-
return a.position - b.position;
|
|
904
|
-
});
|
|
905
|
-
return { stack, clauseWords: clause };
|
|
906
|
-
}
|
|
907
|
-
return { stack: [], clauseWords: [] };
|
|
908
|
-
}
|
|
909
|
-
function parseDecomposition(pattern) {
|
|
910
|
-
const raw = pattern.trim().replace(/\s+/g, " ").toLowerCase();
|
|
911
|
-
if (!raw)
|
|
912
|
-
return [];
|
|
913
|
-
const tokens = [];
|
|
914
|
-
let i = 0;
|
|
915
|
-
while (i < raw.length) {
|
|
916
|
-
while (i < raw.length && raw[i] === " ")
|
|
917
|
-
i++;
|
|
918
|
-
if (i >= raw.length)
|
|
919
|
-
break;
|
|
920
|
-
const ch = raw[i];
|
|
921
|
-
if (ch === "*") {
|
|
922
|
-
tokens.push({ kind: "wildcard" });
|
|
923
|
-
i++;
|
|
924
|
-
continue;
|
|
925
|
-
}
|
|
926
|
-
if (ch === "@") {
|
|
927
|
-
let j2 = i + 1;
|
|
928
|
-
while (j2 < raw.length && raw[j2] !== " ")
|
|
929
|
-
j2++;
|
|
930
|
-
const groupName = raw.slice(i + 1, j2).trim();
|
|
931
|
-
if (groupName.length > 0)
|
|
932
|
-
tokens.push({ kind: "group", groupName });
|
|
933
|
-
i = j2;
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
if (ch === "[") {
|
|
937
|
-
const close = raw.indexOf("]", i + 1);
|
|
938
|
-
if (close === -1) {
|
|
939
|
-
const rest = raw.slice(i).trim();
|
|
940
|
-
if (rest.length > 0)
|
|
941
|
-
tokens.push({ kind: "literal", value: rest });
|
|
942
|
-
break;
|
|
943
|
-
}
|
|
944
|
-
const inside = raw.slice(i + 1, close).trim();
|
|
945
|
-
const options = inside.length > 0 ? inside.split(/\s+/g) : [];
|
|
946
|
-
tokens.push({ kind: "alt", options });
|
|
947
|
-
i = close + 1;
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
let j = i;
|
|
951
|
-
while (j < raw.length && raw[j] !== " ")
|
|
952
|
-
j++;
|
|
953
|
-
const word = raw.slice(i, j).trim();
|
|
954
|
-
if (word.length > 0)
|
|
955
|
-
tokens.push({ kind: "literal", value: word });
|
|
956
|
-
i = j;
|
|
957
|
-
}
|
|
958
|
-
return tokens;
|
|
959
|
-
}
|
|
960
|
-
function tokenMatchesWord(token, word) {
|
|
961
|
-
if (token.kind === "literal")
|
|
962
|
-
return token.value === word;
|
|
963
|
-
if (token.kind === "alt")
|
|
964
|
-
return token.options.includes(word);
|
|
965
|
-
if (token.kind === "group") {
|
|
966
|
-
const groupWords = script.groups[token.groupName];
|
|
967
|
-
if (!groupWords)
|
|
968
|
-
return false;
|
|
969
|
-
return groupWords.includes(word);
|
|
970
|
-
}
|
|
971
|
-
return false;
|
|
972
|
-
}
|
|
973
|
-
function matchDecomposition(tokens, words) {
|
|
974
|
-
const parts = new Array(tokens.length).fill("");
|
|
975
|
-
function backtrack(ti, wi) {
|
|
976
|
-
if (ti === tokens.length)
|
|
977
|
-
return wi === words.length;
|
|
978
|
-
const token = tokens[ti];
|
|
979
|
-
if (token.kind === "wildcard") {
|
|
980
|
-
for (let end = wi;end <= words.length; end++) {
|
|
981
|
-
parts[ti] = words.slice(wi, end).join(" ").trim();
|
|
982
|
-
if (backtrack(ti + 1, end))
|
|
983
|
-
return true;
|
|
984
|
-
}
|
|
985
|
-
return false;
|
|
986
|
-
}
|
|
987
|
-
if (wi >= words.length)
|
|
988
|
-
return false;
|
|
989
|
-
const w = words[wi];
|
|
990
|
-
if (!tokenMatchesWord(token, w))
|
|
991
|
-
return false;
|
|
992
|
-
parts[ti] = w;
|
|
993
|
-
return backtrack(ti + 1, wi + 1);
|
|
994
|
-
}
|
|
995
|
-
if (!backtrack(0, 0))
|
|
996
|
-
return null;
|
|
997
|
-
return { parts };
|
|
998
|
-
}
|
|
999
|
-
function applyReassembly(template, parts) {
|
|
1000
|
-
return template.replace(/\$(\d+)/g, (_m, nRaw) => {
|
|
1001
|
-
const n = Number.parseInt(nRaw, 10);
|
|
1002
|
-
if (!Number.isFinite(n) || n <= 0)
|
|
1003
|
-
return "";
|
|
1004
|
-
const part = parts[n - 1] ?? "";
|
|
1005
|
-
return reflectText(part);
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
function stableKeyForRule(keyword, rule, ruleIndex) {
|
|
1009
|
-
return `${keyword}::${ruleIndex}::${rule.decomposition}`;
|
|
1010
|
-
}
|
|
1011
|
-
function pickNextReassembly(session, keyword, rule, ruleIndex) {
|
|
1012
|
-
const key = stableKeyForRule(keyword, rule, ruleIndex);
|
|
1013
|
-
const current = session.reassemblyIndex.get(key) ?? 0;
|
|
1014
|
-
const idx = current % rule.reassembly.length;
|
|
1015
|
-
session.reassemblyIndex.set(key, (current + 1) % Math.max(1, rule.reassembly.length));
|
|
1016
|
-
return rule.reassembly[idx] ?? "";
|
|
1017
|
-
}
|
|
1018
|
-
function computeWordHash(word) {
|
|
1019
|
-
let h = 0;
|
|
1020
|
-
for (let i = 0;i < word.length; i++) {
|
|
1021
|
-
h = h * 31 + word.charCodeAt(i) >>> 0;
|
|
1022
|
-
}
|
|
1023
|
-
return h;
|
|
1024
|
-
}
|
|
1025
|
-
function chooseDefaultResponse(session) {
|
|
1026
|
-
if (session.limit === 4 && session.memories.length > 0) {
|
|
1027
|
-
const m = session.memories.shift();
|
|
1028
|
-
if (m)
|
|
1029
|
-
return m;
|
|
1030
|
-
}
|
|
1031
|
-
const idx = (session.reassemblyIndex.get("__default__") ?? 0) % script.default.length;
|
|
1032
|
-
session.reassemblyIndex.set("__default__", idx + 1);
|
|
1033
|
-
return script.default[idx] ?? script.default[0] ?? "Please go on.";
|
|
1034
|
-
}
|
|
1035
|
-
function isGoodbye(words) {
|
|
1036
|
-
if (words.length === 0)
|
|
1037
|
-
return false;
|
|
1038
|
-
const first = words[0];
|
|
1039
|
-
return script.goodbyes.some((g) => tokenizeWords(g)[0] === first);
|
|
1040
|
-
}
|
|
1041
|
-
function resolveRedirectKeyword(s) {
|
|
1042
|
-
const trimmed = s.trim();
|
|
1043
|
-
if (!trimmed.startsWith("="))
|
|
1044
|
-
return null;
|
|
1045
|
-
const k = trimmed.slice(1).trim().toLowerCase();
|
|
1046
|
-
return k.length > 0 ? k : null;
|
|
1047
|
-
}
|
|
1048
|
-
function parsePreDirective(s) {
|
|
1049
|
-
const m = s.trim().match(/^:pre\s+(.+?)\s+\(=\s*([^)]+)\s*\)\s*$/i);
|
|
1050
|
-
if (!m)
|
|
1051
|
-
return null;
|
|
1052
|
-
const preText = m[1]?.trim() ?? "";
|
|
1053
|
-
const redirect = m[2]?.trim().toLowerCase() ?? "";
|
|
1054
|
-
if (!preText || !redirect)
|
|
1055
|
-
return null;
|
|
1056
|
-
return { preText, redirect };
|
|
1057
|
-
}
|
|
1058
|
-
function isNewKeyDirective(s) {
|
|
1059
|
-
return s.trim().toLowerCase() === ":newkey" || s.trim().toLowerCase() === "newkey";
|
|
1060
|
-
}
|
|
1061
|
-
function tryRulesForKeyword(session, keyword, entry, words) {
|
|
1062
|
-
for (let i = 0;i < entry.rules.length; i++) {
|
|
1063
|
-
const rule = entry.rules[i];
|
|
1064
|
-
const tokens = parseDecomposition(rule.decomposition);
|
|
1065
|
-
const match = matchDecomposition(tokens, words);
|
|
1066
|
-
if (!match)
|
|
1067
|
-
continue;
|
|
1068
|
-
const picked = pickNextReassembly(session, keyword, rule, i);
|
|
1069
|
-
if (isNewKeyDirective(picked))
|
|
1070
|
-
return { kind: "newkey" };
|
|
1071
|
-
const pre = parsePreDirective(picked);
|
|
1072
|
-
if (pre)
|
|
1073
|
-
return {
|
|
1074
|
-
kind: "pre",
|
|
1075
|
-
preText: pre.preText,
|
|
1076
|
-
redirect: pre.redirect,
|
|
1077
|
-
parts: match.parts
|
|
1078
|
-
};
|
|
1079
|
-
const redirect = resolveRedirectKeyword(picked);
|
|
1080
|
-
if (redirect)
|
|
1081
|
-
return { kind: "redirect", keyword: redirect };
|
|
1082
|
-
return {
|
|
1083
|
-
kind: "response",
|
|
1084
|
-
text: applyReassembly(picked, match.parts).replace(/\s+/g, " ").trim()
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
return { kind: "no_match" };
|
|
1088
|
-
}
|
|
1089
|
-
function maybeRecordMemory(session, entry, words) {
|
|
1090
|
-
const memoryRules = entry.memory;
|
|
1091
|
-
if (!memoryRules || memoryRules.length === 0)
|
|
1092
|
-
return;
|
|
1093
|
-
const last = words.length > 0 ? words[words.length - 1] : "";
|
|
1094
|
-
const chosenIdx = computeWordHash(last) % memoryRules.length;
|
|
1095
|
-
const chosen = memoryRules[chosenIdx];
|
|
1096
|
-
if (!chosen)
|
|
1097
|
-
return;
|
|
1098
|
-
const tokens = parseDecomposition(chosen.decomposition);
|
|
1099
|
-
const match = matchDecomposition(tokens, words);
|
|
1100
|
-
if (!match)
|
|
1101
|
-
return;
|
|
1102
|
-
const responseIdx = computeWordHash(last) % Math.max(1, chosen.reassembly.length);
|
|
1103
|
-
const template = chosen.reassembly[responseIdx] ?? chosen.reassembly[0] ?? "";
|
|
1104
|
-
const response = applyReassembly(template, match.parts).replace(/\s+/g, " ").trim();
|
|
1105
|
-
if (response.length > 0)
|
|
1106
|
-
session.memories.push(response);
|
|
1107
|
-
}
|
|
1108
|
-
function generateElizaResponse(arg1, arg2) {
|
|
1109
|
-
const runtime = typeof arg1 === "string" ? null : arg1;
|
|
1110
|
-
const input = typeof arg1 === "string" ? arg1 : arg2 ?? "";
|
|
1111
|
-
const session = runtime ? getOrCreateSession(runtime) : defaultStandaloneSession;
|
|
1112
|
-
session.limit = session.limit === 4 ? 1 : session.limit + 1;
|
|
1113
|
-
const scanWords = tokenizeForScan(input);
|
|
1114
|
-
const words = tokenizeWords(input);
|
|
1115
|
-
if (words.length === 0)
|
|
1116
|
-
return chooseDefaultResponse(session);
|
|
1117
|
-
if (isGoodbye(words)) {
|
|
1118
|
-
return script.goodbyes[0] ?? "Goodbye.";
|
|
1119
|
-
}
|
|
1120
|
-
const { stack: keywordStack, clauseWords } = selectKeywordStack(scanWords);
|
|
1121
|
-
if (keywordStack.length === 0 || clauseWords.length === 0) {
|
|
1122
|
-
return chooseDefaultResponse(session);
|
|
1123
|
-
}
|
|
1124
|
-
const matchWords = substituteWordsForMatching(clauseWords);
|
|
1125
|
-
for (const found of keywordStack) {
|
|
1126
|
-
maybeRecordMemory(session, found.entry, matchWords);
|
|
1127
|
-
const result = tryRulesForKeyword(session, found.keyword, found.entry, matchWords);
|
|
1128
|
-
if (result.kind === "no_match")
|
|
1129
|
-
continue;
|
|
1130
|
-
if (result.kind === "newkey")
|
|
1131
|
-
continue;
|
|
1132
|
-
if (result.kind === "pre") {
|
|
1133
|
-
const preApplied = applyReassembly(result.preText, result.parts).replace(/\s+/g, " ").trim();
|
|
1134
|
-
const preWords = tokenizeWords(preApplied);
|
|
1135
|
-
const redirectedEntry = keywordIndex.get(result.redirect);
|
|
1136
|
-
if (!redirectedEntry)
|
|
1137
|
-
continue;
|
|
1138
|
-
const redirected = tryRulesForKeyword(session, result.redirect, redirectedEntry, preWords);
|
|
1139
|
-
if (redirected.kind === "response")
|
|
1140
|
-
return redirected.text;
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
if (result.kind === "redirect") {
|
|
1144
|
-
const redirectedEntry = keywordIndex.get(result.keyword);
|
|
1145
|
-
if (!redirectedEntry)
|
|
1146
|
-
continue;
|
|
1147
|
-
const redirected = tryRulesForKeyword(session, result.keyword, redirectedEntry, matchWords);
|
|
1148
|
-
if (redirected.kind === "response")
|
|
1149
|
-
return redirected.text;
|
|
1150
|
-
continue;
|
|
1151
|
-
}
|
|
1152
|
-
if (result.kind === "response")
|
|
1153
|
-
return result.text;
|
|
1154
|
-
}
|
|
1155
|
-
return chooseDefaultResponse(session);
|
|
1156
|
-
}
|
|
1157
|
-
function getElizaGreeting() {
|
|
1158
|
-
return script.greetings[1] ?? script.greetings[0] ?? "How do you do. Please tell me your problem.";
|
|
1159
|
-
}
|
|
1160
|
-
function extractUserMessage(prompt) {
|
|
1161
|
-
const match = prompt.match(/(?:User|Human|You):\s*(.+?)(?:\n|$)/i);
|
|
1162
|
-
return match ? match[1].trim() : prompt.trim();
|
|
1163
|
-
}
|
|
1164
|
-
async function handleTextLarge(_runtime, params) {
|
|
1165
|
-
const input = extractUserMessage(params.prompt);
|
|
1166
|
-
return generateElizaResponse(_runtime, input);
|
|
1167
|
-
}
|
|
1168
|
-
async function handleTextSmall(runtime, params) {
|
|
1169
|
-
return handleTextLarge(runtime, params);
|
|
1170
|
-
}
|
|
1171
|
-
// plugin.ts
|
|
1172
|
-
var import_core2 = require("@elizaos/core");
|
|
1173
|
-
|
|
1174
|
-
// actions/generateResponse.ts
|
|
1175
|
-
var import_core = require("@elizaos/core");
|
|
1176
|
-
|
|
1177
|
-
// generated/specs/specs.ts
|
|
1178
|
-
var coreActionsSpec = {
|
|
1179
|
-
version: "1.0.0",
|
|
1180
|
-
actions: [
|
|
1181
|
-
{
|
|
1182
|
-
name: "generate-response",
|
|
1183
|
-
description: "Generate an ELIZA response for user input using classic pattern matching.",
|
|
1184
|
-
similes: ["ELIZA_RESPOND", "ELIZA_CHAT", "CLASSIC_ELIZA"],
|
|
1185
|
-
parameters: []
|
|
1186
|
-
}
|
|
1187
|
-
]
|
|
1188
|
-
};
|
|
1189
|
-
var allActionsSpec = {
|
|
1190
|
-
version: "1.0.0",
|
|
1191
|
-
actions: [
|
|
1192
|
-
{
|
|
1193
|
-
name: "generate-response",
|
|
1194
|
-
description: "Generate an ELIZA response for user input using classic pattern matching.",
|
|
1195
|
-
similes: ["ELIZA_RESPOND", "ELIZA_CHAT", "CLASSIC_ELIZA"],
|
|
1196
|
-
parameters: []
|
|
1197
|
-
}
|
|
1198
|
-
]
|
|
1199
|
-
};
|
|
1200
|
-
var coreProvidersSpec = {
|
|
1201
|
-
version: "1.0.0",
|
|
1202
|
-
providers: [
|
|
1203
|
-
{
|
|
1204
|
-
name: "eliza-greeting",
|
|
1205
|
-
description: "",
|
|
1206
|
-
dynamic: true
|
|
1207
|
-
}
|
|
1208
|
-
]
|
|
1209
|
-
};
|
|
1210
|
-
var allProvidersSpec = {
|
|
1211
|
-
version: "1.0.0",
|
|
1212
|
-
providers: [
|
|
1213
|
-
{
|
|
1214
|
-
name: "eliza-greeting",
|
|
1215
|
-
description: "",
|
|
1216
|
-
dynamic: true
|
|
1217
|
-
}
|
|
1218
|
-
]
|
|
1219
|
-
};
|
|
1220
|
-
var coreEvaluatorsSpec = {
|
|
1221
|
-
version: "1.0.0",
|
|
1222
|
-
evaluators: []
|
|
1223
|
-
};
|
|
1224
|
-
var allEvaluatorsSpec = {
|
|
1225
|
-
version: "1.0.0",
|
|
1226
|
-
evaluators: []
|
|
1227
|
-
};
|
|
1228
|
-
var coreActionDocs = coreActionsSpec.actions;
|
|
1229
|
-
var allActionDocs = allActionsSpec.actions;
|
|
1230
|
-
var coreProviderDocs = coreProvidersSpec.providers;
|
|
1231
|
-
var allProviderDocs = allProvidersSpec.providers;
|
|
1232
|
-
var coreEvaluatorDocs = coreEvaluatorsSpec.evaluators;
|
|
1233
|
-
var allEvaluatorDocs = allEvaluatorsSpec.evaluators;
|
|
1234
|
-
|
|
1235
|
-
// generated/specs/spec-helpers.ts
|
|
1236
|
-
var coreActionMap = new Map(coreActionDocs.map((doc) => [doc.name, doc]));
|
|
1237
|
-
var allActionMap = new Map(allActionDocs.map((doc) => [doc.name, doc]));
|
|
1238
|
-
var coreProviderMap = new Map(coreProviderDocs.map((doc) => [doc.name, doc]));
|
|
1239
|
-
var allProviderMap = new Map(allProviderDocs.map((doc) => [doc.name, doc]));
|
|
1240
|
-
var coreEvaluatorMap = new Map(coreEvaluatorDocs.map((doc) => [doc.name, doc]));
|
|
1241
|
-
var allEvaluatorMap = new Map(allEvaluatorDocs.map((doc) => [doc.name, doc]));
|
|
1242
|
-
function getActionSpec(name) {
|
|
1243
|
-
return coreActionMap.get(name) ?? allActionMap.get(name);
|
|
1244
|
-
}
|
|
1245
|
-
function requireActionSpec(name) {
|
|
1246
|
-
const spec = getActionSpec(name);
|
|
1247
|
-
if (!spec) {
|
|
1248
|
-
throw new Error(`Action spec not found: ${name}`);
|
|
1249
|
-
}
|
|
1250
|
-
return spec;
|
|
1251
|
-
}
|
|
1252
|
-
function getProviderSpec(name) {
|
|
1253
|
-
return coreProviderMap.get(name) ?? allProviderMap.get(name);
|
|
1254
|
-
}
|
|
1255
|
-
function requireProviderSpec(name) {
|
|
1256
|
-
const spec = getProviderSpec(name);
|
|
1257
|
-
if (!spec) {
|
|
1258
|
-
throw new Error(`Provider spec not found: ${name}`);
|
|
1259
|
-
}
|
|
1260
|
-
return spec;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
// actions/generateResponse.ts
|
|
1264
|
-
var spec = requireActionSpec("generate-response");
|
|
1265
|
-
var generateResponseAction = {
|
|
1266
|
-
name: spec.name,
|
|
1267
|
-
similes: spec.similes ? [...spec.similes] : [],
|
|
1268
|
-
description: spec.description,
|
|
1269
|
-
validate: async (_runtime, _message, _state) => {
|
|
1270
|
-
return true;
|
|
1271
|
-
},
|
|
1272
|
-
handler: async (runtime, message, _state, _options, callback) => {
|
|
1273
|
-
const userInput = typeof message.content === "object" && message.content !== null ? message.content.text || "" : String(message.content || "");
|
|
1274
|
-
if (!userInput.trim()) {
|
|
1275
|
-
if (callback) {
|
|
1276
|
-
await callback({
|
|
1277
|
-
text: "I need something to respond to. What would you like to talk about?",
|
|
1278
|
-
source: message.content.source
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
return { success: false, error: "No user input provided" };
|
|
1282
|
-
}
|
|
1283
|
-
try {
|
|
1284
|
-
const response = await runtime.useModel(import_core.ModelType.TEXT_LARGE, {
|
|
1285
|
-
prompt: userInput
|
|
1286
|
-
});
|
|
1287
|
-
if (callback) {
|
|
1288
|
-
await callback({
|
|
1289
|
-
text: response,
|
|
1290
|
-
source: message.content.source
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
return { success: true, text: response };
|
|
1294
|
-
} catch (error) {
|
|
1295
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1296
|
-
if (callback) {
|
|
1297
|
-
await callback({
|
|
1298
|
-
text: "I encountered an issue. Please try again.",
|
|
1299
|
-
source: message.content.source
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
return { success: false, error: errorMessage };
|
|
1303
|
-
}
|
|
1304
|
-
},
|
|
1305
|
-
examples: spec.examples ?? []
|
|
1306
|
-
};
|
|
1307
|
-
// providers/elizaGreeting.ts
|
|
1308
|
-
var spec2 = requireProviderSpec("eliza-greeting");
|
|
1309
|
-
var elizaGreetingProvider = {
|
|
1310
|
-
name: spec2.name,
|
|
1311
|
-
dynamic: true,
|
|
1312
|
-
get: async (_runtime, _message, _state) => {
|
|
1313
|
-
const greeting = getElizaGreeting();
|
|
1314
|
-
return {
|
|
1315
|
-
data: {
|
|
1316
|
-
greeting
|
|
1317
|
-
},
|
|
1318
|
-
values: {
|
|
1319
|
-
greeting
|
|
1320
|
-
},
|
|
1321
|
-
text: greeting
|
|
1322
|
-
};
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
// plugin.ts
|
|
1326
|
-
var elizaClassicPlugin = {
|
|
1327
|
-
name: "eliza-classic",
|
|
1328
|
-
description: "Classic ELIZA pattern matching psychotherapist - no LLM required",
|
|
1329
|
-
priority: 100,
|
|
1330
|
-
actions: [generateResponseAction],
|
|
1331
|
-
providers: [elizaGreetingProvider],
|
|
1332
|
-
models: {
|
|
1333
|
-
[import_core2.ModelType.TEXT_LARGE]: async (runtime, params) => {
|
|
1334
|
-
return handleTextLarge(runtime, params);
|
|
1335
|
-
},
|
|
1336
|
-
[import_core2.ModelType.TEXT_SMALL]: async (runtime, params) => {
|
|
1337
|
-
return handleTextSmall(runtime, params);
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
async init(_config, _runtime) {
|
|
1341
|
-
import_core2.logger.info({ src: "plugin:eliza-classic" }, "ELIZA pattern matching initialized");
|
|
1342
|
-
},
|
|
1343
|
-
tests: [
|
|
1344
|
-
{
|
|
1345
|
-
name: "eliza_classic_plugin_tests",
|
|
1346
|
-
tests: [
|
|
1347
|
-
{
|
|
1348
|
-
name: "eliza_test_greeting",
|
|
1349
|
-
fn: async (runtime) => {
|
|
1350
|
-
const response = await runtime.useModel(import_core2.ModelType.TEXT_LARGE, {
|
|
1351
|
-
prompt: "hello"
|
|
1352
|
-
});
|
|
1353
|
-
if (typeof response !== "string" || response.length === 0) {
|
|
1354
|
-
throw new Error("Greeting should return non-empty string");
|
|
1355
|
-
}
|
|
1356
|
-
import_core2.logger.info(`[ELIZA Test] Greeting: "${response}"`);
|
|
1357
|
-
}
|
|
1358
|
-
},
|
|
1359
|
-
{
|
|
1360
|
-
name: "eliza_test_feeling_sad",
|
|
1361
|
-
fn: async (runtime) => {
|
|
1362
|
-
const response = await runtime.useModel(import_core2.ModelType.TEXT_LARGE, {
|
|
1363
|
-
prompt: "I am sad today"
|
|
1364
|
-
});
|
|
1365
|
-
if (typeof response !== "string" || response.length === 0) {
|
|
1366
|
-
throw new Error("Response should be non-empty string");
|
|
1367
|
-
}
|
|
1368
|
-
import_core2.logger.info(`[ELIZA Test] Sad response: "${response}"`);
|
|
1369
|
-
}
|
|
1370
|
-
},
|
|
1371
|
-
{
|
|
1372
|
-
name: "eliza_test_family",
|
|
1373
|
-
fn: async (runtime) => {
|
|
1374
|
-
const response = await runtime.useModel(import_core2.ModelType.TEXT_LARGE, {
|
|
1375
|
-
prompt: "My mother is very kind"
|
|
1376
|
-
});
|
|
1377
|
-
if (typeof response !== "string" || response.length === 0) {
|
|
1378
|
-
throw new Error("Response should be non-empty string");
|
|
1379
|
-
}
|
|
1380
|
-
import_core2.logger.info(`[ELIZA Test] Family response: "${response}"`);
|
|
1381
|
-
}
|
|
1382
|
-
},
|
|
1383
|
-
{
|
|
1384
|
-
name: "eliza_test_computer",
|
|
1385
|
-
fn: async (runtime) => {
|
|
1386
|
-
const response = await runtime.useModel(import_core2.ModelType.TEXT_LARGE, {
|
|
1387
|
-
prompt: "I think computers are fascinating"
|
|
1388
|
-
});
|
|
1389
|
-
if (typeof response !== "string" || response.length === 0) {
|
|
1390
|
-
throw new Error("Response should be non-empty string");
|
|
1391
|
-
}
|
|
1392
|
-
import_core2.logger.info(`[ELIZA Test] Computer response: "${response}"`);
|
|
1393
|
-
}
|
|
1394
|
-
},
|
|
1395
|
-
{
|
|
1396
|
-
name: "eliza_test_text_small",
|
|
1397
|
-
fn: async (runtime) => {
|
|
1398
|
-
const response = await runtime.useModel(import_core2.ModelType.TEXT_SMALL, {
|
|
1399
|
-
prompt: "Can you help me?"
|
|
1400
|
-
});
|
|
1401
|
-
if (typeof response !== "string" || response.length === 0) {
|
|
1402
|
-
throw new Error("TEXT_SMALL should return non-empty string");
|
|
1403
|
-
}
|
|
1404
|
-
import_core2.logger.info(`[ELIZA Test] TEXT_SMALL: "${response}"`);
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
]
|
|
1408
|
-
}
|
|
1409
|
-
]
|
|
1410
|
-
};
|
|
1411
|
-
|
|
1412
|
-
//# debugId=272EE8A7F46C9E0E64756E2164756E21
|
|
1413
|
-
//# sourceMappingURL=index.node.cjs.map
|