tpmkms_4wp 9.3.0-beta.1 → 9.3.0-beta.2

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.
@@ -0,0 +1,47 @@
1
+ {
2
+ "configs": [
3
+ {
4
+ "operators": [
5
+ "([remind] (self/*) (*)*)"
6
+ ],
7
+ "bridges": [
8
+ {
9
+ "id": "remind",
10
+ "isA": [
11
+ "verb"
12
+ ],
13
+ "bridge": "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }",
14
+ "semantic": "async ({api, gsp, context}) => {\n const text = await gsp(context.reminder.slice(1));\n api.add({ text });\n }"
15
+ }
16
+ ]
17
+ },
18
+ {
19
+ "apply": "({ask, api}) => {\n ask([\n {\n where: where(),\n oneShot: false,\n onNevermind: ({verbatim, ...args}) => {\n // this is cross km boundaries from the dialogues km to this one so the api if for dialogs.\n // i need to get the one for fastfood here.\n const api = args.kms.fastfood.api\n const needsDrink = askAbout({ args, api })\n for (const item of needsDrink) {\n api.remove(item)\n }\n },\n\n matchq: (args) => args.api.askAbout(args).length > 0 && args.context.marker == 'controlEnd',\n applyq: (args) => {\n args.context.cascade = false\n const items = askAbout(args)\n const item = items[0]\n debugger;\n debugger\n },\n\n matchr: (args) => {\n if (args.isA(args.context.marker, 'drink') && askAbout(args).length > 0) {\n const needsDrink = askAbout(args)\n if (args.api.isAvailableModification(needsDrink[0].food, { ...args.context , id: args.context.value })) {\n return true\n }\n }\n return false\n },\n applyr: (args) => {\n // TODO check for is available for all modifications\n const needsDrink = askAbout(args)\n const { api, context } = args\n if (isMany(context)) {\n let count = getCount(context) || Number.MAX_SAFE_INTEGER\n for (const item of needsDrink) {\n if (count < 1) {\n break\n }\n count -= 1\n api.addDrink(item.item_id, { id: context.value })\n }\n } else {\n const item_id = needsDrink[0].item_id\n api.addDrink(item_id, { id: context.value })\n }\n }\n },\n ])\n }"
20
+ }
21
+ ],
22
+ "resultss": [
23
+ {
24
+ "extraConfig": true,
25
+ "operators": [
26
+ "([remind] (self/*) (*)*)"
27
+ ],
28
+ "bridges": [
29
+ {
30
+ "id": "remind",
31
+ "isA": [
32
+ "verb"
33
+ ],
34
+ "bridge": "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }"
35
+ }
36
+ ]
37
+ },
38
+ {
39
+ "apply": "({ask, api}) => {\n ask([\n {\n where: where(),\n oneShot: false,\n onNevermind: ({verbatim, ...args}) => {\n // this is cross km boundaries from the dialogues km to this one so the api if for dialogs.\n // i need to get the one for fastfood here.\n const api = args.kms.fastfood.api\n const needsDrink = askAbout({ args, api })\n for (const item of needsDrink) {\n api.remove(item)\n }\n },\n\n matchq: (args) => args.api.askAbout(args).length > 0 && args.context.marker == 'controlEnd',\n applyq: (args) => {\n args.context.cascade = false\n const items = askAbout(args)\n const item = items[0]\n debugger;\n debugger\n },\n\n matchr: (args) => {\n if (args.isA(args.context.marker, 'drink') && askAbout(args).length > 0) {\n const needsDrink = askAbout(args)\n if (args.api.isAvailableModification(needsDrink[0].food, { ...args.context , id: args.context.value })) {\n return true\n }\n }\n return false\n },\n applyr: (args) => {\n // TODO check for is available for all modifications\n const needsDrink = askAbout(args)\n const { api, context } = args\n if (isMany(context)) {\n let count = getCount(context) || Number.MAX_SAFE_INTEGER\n for (const item of needsDrink) {\n if (count < 1) {\n break\n }\n count -= 1\n api.addDrink(item.item_id, { id: context.value })\n }\n } else {\n const item_id = needsDrink[0].item_id\n api.addDrink(item_id, { id: context.value })\n }\n }\n },\n ])\n }"
40
+ }
41
+ ],
42
+ "fragments": [],
43
+ "semantics": [],
44
+ "associations": [],
45
+ "summaries": [],
46
+ "learned_contextual_priorities": []
47
+ }
@@ -0,0 +1,198 @@
1
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const { defaultContextCheck } = require('./helpers')
3
+ const reminders_tests = require('./reminders.test.json')
4
+ const reminders_instance = require('./reminders.instance.json')
5
+ const selfKM = require('./self')
6
+ const dates = require('./dates')
7
+ const helpers = require('./helpers')
8
+
9
+ class API {
10
+ initialize({ objects }) {
11
+ this._objects = objects
12
+ this._objects.reminders = []
13
+ this._objects.id = 0
14
+ }
15
+
16
+ add(reminder) {
17
+ const id = ++this._objects.id
18
+ this._objects.reminders.push({ ...reminder, id })
19
+ }
20
+
21
+ askAbout() {
22
+ const items = []
23
+ for (const item of this._objects.reminders) {
24
+ if (!item.when) {
25
+ items.push({ when: true, text: item.text, id: item.id })
26
+ }
27
+ }
28
+ return items
29
+ }
30
+
31
+ show() {
32
+ if (this._objects.reminders.length == 0) {
33
+ return "There are no reminders"
34
+ }
35
+ let s = 'The reminders are\n'
36
+ let counter = 1
37
+ for (const item of this._objects.reminders) {
38
+ s += ` ${counter}. ${item.text}\n`
39
+ counter += 1
40
+ }
41
+ return s;
42
+ // -> return a table object. then have ability to talk about the table. maybe later let's focus on this for now
43
+ }
44
+
45
+ delete_reminder(ordinal) {
46
+ if (ordinal < 1 || ordinal > this._objects.reminders.length) {
47
+ return `Not possible`
48
+ }
49
+ this._objects.reminders = this._objects.reminders.splice(ordinal, 1)
50
+ }
51
+
52
+ update(update) {
53
+ for (const item of this._objects.reminders) {
54
+ if (item.id == update.id) {
55
+ Object.assign(item, update)
56
+ return
57
+ }
58
+ }
59
+
60
+ }
61
+ }
62
+
63
+ /*
64
+ remind me to go to the store tuesday
65
+ */
66
+ const template = {
67
+ configs: [
68
+ {
69
+ operators: [
70
+ "([remind] (self/*) (*)*)",
71
+ "([reminderTime|])",
72
+ "([show] ([reminders]))",
73
+ "([delete_reminders|delete,cancel] (number/*))",
74
+ ],
75
+ bridges: [
76
+ {
77
+ id: 'remind',
78
+ isA: ['verb'],
79
+ bridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }",
80
+ semantic: async ({api, gsp, context}) => {
81
+ const text = await gsp(context.reminder.slice(1));
82
+ api.add({ text });
83
+ },
84
+ },
85
+ {
86
+ id: 'reminderTime',
87
+ children: [
88
+ 'month_dates',
89
+ ],
90
+ },
91
+ {
92
+ id: 'reminders',
93
+ isA: ['noun'],
94
+ },
95
+ {
96
+ id: 'show',
97
+ isA: ['verb'],
98
+ bridge: "{ ...next(operator), operator: operator, reminders: after[0], interpolate: '${operator} ${reminders}' }",
99
+ semantic: ({context, api, verbatim}) => {
100
+ verbatim(api.show())
101
+ }
102
+ },
103
+ {
104
+ id: 'delete_reminders',
105
+ isA: ['verb'],
106
+ bridge: "{ ...next(operator), operator: operator, reminders: after[0], interpolate: '${operator} ${reminders}' }",
107
+ semantic: ({context, api, verbatim}) => {
108
+ const s = api.delete_reminder(context.reminders.value)
109
+ if (s) {
110
+ verbatim(s)
111
+ }
112
+ }
113
+ },
114
+ ]
115
+ },
116
+ ({ask, api}) => {
117
+ ask([
118
+ {
119
+ where: where(),
120
+ oneShot: false,
121
+ onNevermind: ({verbatim, ...args}) => {
122
+ // this is cross km boundaries from the dialogues km to this one so the api if for dialogs.
123
+ // i need to get the one for fastfood here.
124
+ const api = args.kms.fastfood.api
125
+ const needsDrink = askAbout({ args, api })
126
+ for (const item of needsDrink) {
127
+ api.remove(item)
128
+ }
129
+ },
130
+
131
+ matchq: ({ api, context }) => api.askAbout().length > 0 && context.marker == 'controlEnd',
132
+ applyq: ({ api, context }) => {
133
+ context.cascade = false
134
+ const items = api.askAbout()
135
+ const item = items[0]
136
+ return 'When should I remind you to ' + item.text;
137
+ },
138
+
139
+ matchr: ({ isA, api, context }) => {
140
+ if (isA(context.marker, 'reminderTime') && api.askAbout().length > 0) {
141
+ return true
142
+ }
143
+ return false
144
+ },
145
+ applyr: ({ context, api }) => {
146
+ const items = api.askAbout()
147
+ api.update({ id: items[0].id, when: context })
148
+ // TODO check for is available for all modifications
149
+ /*
150
+ const needsDrink = askAbout(args)
151
+ const { api, context } = args
152
+ if (isMany(context)) {
153
+ let count = getCount(context) || Number.MAX_SAFE_INTEGER
154
+ for (const item of needsDrink) {
155
+ if (count < 1) {
156
+ break
157
+ }
158
+ count -= 1
159
+ api.addDrink(item.item_id, { id: context.value })
160
+ }
161
+ } else {
162
+ const item_id = needsDrink[0].item_id
163
+ api.addDrink(item_id, { id: context.value })
164
+ }
165
+ */
166
+ }
167
+ },
168
+ ])
169
+ }
170
+ ],
171
+ }
172
+
173
+ knowledgeModule( {
174
+ config: { name: 'reminders' },
175
+ includes: [dates, selfKM],
176
+ api: () => new API(),
177
+
178
+ module,
179
+ description: 'talking about reminders',
180
+ test: {
181
+ name: './reminders.test.json',
182
+ contents: reminders_tests,
183
+ checks: {
184
+ context: defaultContextCheck(['who', 'reminder']),
185
+ objects: [
186
+ {
187
+ property: 'reminders',
188
+ filter: [ 'text', 'when' ],
189
+ }
190
+ ],
191
+ },
192
+ },
193
+ template: {
194
+ template,
195
+ instance: reminders_instance,
196
+ },
197
+
198
+ })