mojulo 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +53 -4
  2. package/lib/audit-logger-new.js +11 -0
  3. package/lib/auth/gate.js +25 -0
  4. package/lib/auth/service.js +17 -0
  5. package/lib/auth/session.js +63 -0
  6. package/lib/builder/chat-processor.js +607 -0
  7. package/lib/builder/composer-bridge.js +82 -0
  8. package/lib/builder/evaluator.js +159 -0
  9. package/lib/builder/executor.js +252 -0
  10. package/lib/builder/index.js +48 -0
  11. package/lib/builder/session.js +248 -0
  12. package/lib/builder/system-prompt.js +422 -0
  13. package/lib/builder/tone-presets.js +75 -0
  14. package/lib/builder/tool-executors.js +1418 -0
  15. package/lib/builder/tools.js +338 -0
  16. package/lib/builder/validators.js +239 -0
  17. package/lib/composer/composer.js +225 -0
  18. package/lib/composer/index.js +40 -0
  19. package/lib/composer/protocols/00_base.txt +19 -0
  20. package/lib/composer/protocols/01_knowledge.txt +9 -0
  21. package/lib/composer/protocols/02_form-gathering.txt +32 -0
  22. package/lib/composer/protocols/03_appointments.txt +16 -0
  23. package/lib/composer/protocols/04_triage.txt +15 -0
  24. package/lib/composer/protocols/05_optical-read.txt +22 -0
  25. package/lib/composer/response-builder.js +98 -0
  26. package/lib/config-builder.js +650 -0
  27. package/lib/db/ids.js +10 -0
  28. package/lib/db/index.js +179 -0
  29. package/lib/db/repositories/apiKeys.js +72 -0
  30. package/lib/db/repositories/auditLogs.js +12 -0
  31. package/lib/db/repositories/botSpaces.js +12 -0
  32. package/lib/db/repositories/builderSessions.js +312 -0
  33. package/lib/db/repositories/deploymentEvents.js +12 -0
  34. package/lib/db/repositories/deployments.js +385 -0
  35. package/lib/db/repositories/documents.js +68 -0
  36. package/lib/db/repositories/mcpJobs.js +84 -0
  37. package/lib/deployers/bot-fleet.js +110 -0
  38. package/lib/deployers/bot-proxy.js +72 -0
  39. package/lib/deployers/build.js +89 -0
  40. package/lib/deployers/cloud-deploy.js +310 -0
  41. package/lib/deployers/docker.js +439 -0
  42. package/lib/deployers/fly.js +432 -0
  43. package/lib/deployers/index.js +38 -0
  44. package/lib/deployment-auth.js +36 -0
  45. package/lib/document-parser.js +171 -0
  46. package/lib/embedder/chunker.js +93 -0
  47. package/lib/embedder/local.js +101 -0
  48. package/lib/embedder/preview-rag.js +93 -0
  49. package/lib/envelope-schema.js +54 -0
  50. package/lib/fleet/scoped-sql.js +342 -0
  51. package/lib/form-schema-config/base.js +135 -0
  52. package/lib/form-schema-config/index.js +286 -0
  53. package/lib/form-schema-config/locales/af-ZA.js +153 -0
  54. package/lib/form-schema-config/locales/ar-AE.js +142 -0
  55. package/lib/form-schema-config/locales/ar-SA.js +164 -0
  56. package/lib/form-schema-config/locales/de-DE.js +152 -0
  57. package/lib/form-schema-config/locales/en-AU.js +161 -0
  58. package/lib/form-schema-config/locales/en-CA.js +115 -0
  59. package/lib/form-schema-config/locales/en-GB.js +132 -0
  60. package/lib/form-schema-config/locales/en-IN.js +219 -0
  61. package/lib/form-schema-config/locales/en-MY.js +171 -0
  62. package/lib/form-schema-config/locales/en-NG.js +198 -0
  63. package/lib/form-schema-config/locales/en-PH.js +186 -0
  64. package/lib/form-schema-config/locales/en-SG.js +153 -0
  65. package/lib/form-schema-config/locales/en-US.js +138 -0
  66. package/lib/form-schema-config/locales/es-ES.js +171 -0
  67. package/lib/form-schema-config/locales/es-MX.js +193 -0
  68. package/lib/form-schema-config/locales/fr-CA.js +138 -0
  69. package/lib/form-schema-config/locales/fr-FR.js +155 -0
  70. package/lib/form-schema-config/locales/hi-IN.js +219 -0
  71. package/lib/form-schema-config/locales/it-IT.js +157 -0
  72. package/lib/form-schema-config/locales/ja-JP.js +169 -0
  73. package/lib/form-schema-config/locales/ko-KR.js +140 -0
  74. package/lib/form-schema-config/locales/nl-NL.js +149 -0
  75. package/lib/form-schema-config/locales/pt-BR.js +168 -0
  76. package/lib/form-schema-config/locales/zh-CN.js +172 -0
  77. package/lib/form-schema-config/locales/zh-HK.js +142 -0
  78. package/lib/form-structure-schema.js +191 -0
  79. package/lib/llm-providers.js +828 -0
  80. package/lib/markdown.js +197 -0
  81. package/lib/mcp/catalysts/appointment-to-calendar.md +84 -0
  82. package/lib/mcp/catalysts/conversations-to-channel-digest.md +104 -0
  83. package/lib/mcp/catalysts/document-extract-to-store.md +92 -0
  84. package/lib/mcp/catalysts/knowledge-gap-miner.md +96 -0
  85. package/lib/mcp/catalysts/loader.js +144 -0
  86. package/lib/mcp/catalysts/qualify-lead-to-crm.md +83 -0
  87. package/lib/mcp/catalysts/scan-conversations-for-signal.md +92 -0
  88. package/lib/mcp/catalysts/submission-to-ticket.md +83 -0
  89. package/lib/mcp/catalysts/submissions-to-warehouse.md +103 -0
  90. package/lib/mcp/catalysts/weekly-submissions-digest.md +82 -0
  91. package/lib/mcp/jobs.js +64 -0
  92. package/lib/mcp/server.js +184 -0
  93. package/lib/mcp/session-binding.js +130 -0
  94. package/lib/mcp/tools/build.js +123 -0
  95. package/lib/mcp/tools/catalysts.js +477 -0
  96. package/lib/mcp/tools/context.js +325 -0
  97. package/lib/mcp/tools/fleet.js +391 -0
  98. package/lib/mcp/tools/jobs-tools.js +240 -0
  99. package/lib/mcp/tools/operate.js +314 -0
  100. package/lib/preview/build-preview-config.js +136 -0
  101. package/lib/rate-limiter.js +11 -0
  102. package/lib/resolve-api-key.js +142 -0
  103. package/lib/storage/index.js +40 -0
  104. package/messages/de.json +2136 -0
  105. package/messages/en.json +2136 -0
  106. package/messages/es.json +2136 -0
  107. package/messages/fr.json +2136 -0
  108. package/messages/it.json +2136 -0
  109. package/messages/ja.json +2136 -0
  110. package/messages/ko.json +2136 -0
  111. package/messages/nl.json +2136 -0
  112. package/messages/pl.json +2136 -0
  113. package/messages/pt.json +2136 -0
  114. package/messages/ru.json +2136 -0
  115. package/messages/uk.json +2136 -0
  116. package/messages/zh.json +2136 -0
  117. package/package.json +61 -5
  118. package/scripts/mcp-config.mjs +162 -0
  119. package/scripts/mcp-stdio-loader.mjs +42 -0
  120. package/scripts/mcp-stdio.mjs +108 -0
  121. package/scripts/mojulo-paths.mjs +48 -0
@@ -0,0 +1,191 @@
1
+ // Canonical form-structure shape for the AI-powered form generator.
2
+ // Consumed by generateStructured() in control/lib/llm-providers.js — the
3
+ // OpenAI / Anthropic / Bedrock adapters all key off this artifact.
4
+ //
5
+ // Two variants:
6
+ // FORM_STRUCTURE_SCHEMA — canonical; used by Anthropic tool_use
7
+ // and Bedrock Converse toolSpec, whose
8
+ // JSON-schema validators are permissive
9
+ // toStrictFormStructureSchema() — OpenAI strict-mode-compatible derivative:
10
+ // every property in `required`, no
11
+ // `additionalProperties: true`, optional
12
+ // keys typed as ["X", "null"]
13
+ //
14
+ // Control-plane only. No mirror in lite-template/ — the bot runtime does
15
+ // not generate forms.
16
+
17
+ const FIELD_TYPES = [
18
+ 'text', 'email', 'tel', 'url', 'date', 'number',
19
+ 'dropdown', 'checkbox', 'textarea', 'radio',
20
+ ];
21
+
22
+ const INPUT_MODES = ['numeric', 'tel', 'email', 'decimal', 'url'];
23
+
24
+ const CONDITION_SCHEMA = {
25
+ oneOf: [
26
+ {
27
+ type: 'object',
28
+ additionalProperties: false,
29
+ required: ['branch'],
30
+ properties: {
31
+ branch: { type: 'string' },
32
+ not: { type: 'boolean' },
33
+ },
34
+ },
35
+ {
36
+ type: 'object',
37
+ additionalProperties: false,
38
+ required: ['logic', 'branches'],
39
+ properties: {
40
+ logic: { type: 'string', enum: ['and', 'or'] },
41
+ branches: { type: 'array', items: { type: 'string' }, minItems: 1 },
42
+ },
43
+ },
44
+ ],
45
+ };
46
+
47
+ const FIELD_SCHEMA = {
48
+ type: 'object',
49
+ additionalProperties: false,
50
+ required: ['id', 'label', 'type', 'required'],
51
+ properties: {
52
+ id: { type: 'string' },
53
+ label: { type: 'string' },
54
+ type: { type: 'string', enum: FIELD_TYPES },
55
+ required: { type: 'boolean' },
56
+ placeholder: { type: 'string' },
57
+ pattern: { type: 'string' },
58
+ patternError: { type: 'string' },
59
+ autocomplete: { type: 'string' },
60
+ inputMode: { type: 'string', enum: INPUT_MODES },
61
+ pii: { type: 'boolean' },
62
+ sensitive: { type: 'boolean' },
63
+ helpText: { type: 'string' },
64
+ maxLength: { type: 'integer', minimum: 1 },
65
+ rows: { type: 'integer', minimum: 1 },
66
+ min: { type: 'number' },
67
+ max: { type: 'number' },
68
+ options: {
69
+ type: 'array',
70
+ items: {
71
+ type: 'object',
72
+ additionalProperties: false,
73
+ required: ['value', 'label'],
74
+ properties: {
75
+ value: { type: 'string' },
76
+ label: { type: 'string' },
77
+ },
78
+ },
79
+ },
80
+ condition: CONDITION_SCHEMA,
81
+ },
82
+ };
83
+
84
+ const SECTION_SCHEMA = {
85
+ type: 'object',
86
+ additionalProperties: false,
87
+ required: ['id', 'label', 'fields'],
88
+ properties: {
89
+ id: { type: 'string' },
90
+ label: { type: 'string' },
91
+ fields: { type: 'array', items: FIELD_SCHEMA, minItems: 1 },
92
+ condition: CONDITION_SCHEMA,
93
+ },
94
+ };
95
+
96
+ export const FORM_STRUCTURE_SCHEMA = {
97
+ type: 'object',
98
+ additionalProperties: false,
99
+ required: ['sections'],
100
+ properties: {
101
+ branches: { type: 'array', items: { type: 'string' } },
102
+ sections: { type: 'array', items: SECTION_SCHEMA, minItems: 1 },
103
+ },
104
+ };
105
+
106
+ // OpenAI structured outputs (strict mode) requires:
107
+ // - every key in `properties` listed in `required`
108
+ // - no `additionalProperties: true` — must be `false` or a schema
109
+ // - `oneOf` only at the top level of a property (not as the property value
110
+ // of another property) — we collapse CONDITION_SCHEMA into a single
111
+ // object with all four keys nullable and let the model pick the shape
112
+ // Optional keys become ["X", "null"] so the model can return null when unset.
113
+ // The route then strips nulls before responding so downstream consumers see
114
+ // the canonical "absent key" shape.
115
+ export function toStrictFormStructureSchema() {
116
+ const conditionSchema = {
117
+ type: ['object', 'null'],
118
+ additionalProperties: false,
119
+ required: ['branch', 'not', 'logic', 'branches'],
120
+ properties: {
121
+ branch: { type: ['string', 'null'] },
122
+ not: { type: ['boolean', 'null'] },
123
+ logic: { type: ['string', 'null'], enum: ['and', 'or', null] },
124
+ branches: { type: ['array', 'null'], items: { type: 'string' } },
125
+ },
126
+ };
127
+
128
+ const fieldSchema = {
129
+ type: 'object',
130
+ additionalProperties: false,
131
+ required: [
132
+ 'id', 'label', 'type', 'required',
133
+ 'placeholder', 'pattern', 'patternError', 'autocomplete', 'inputMode',
134
+ 'pii', 'sensitive', 'helpText', 'maxLength', 'rows', 'min', 'max',
135
+ 'options', 'condition',
136
+ ],
137
+ properties: {
138
+ id: { type: 'string' },
139
+ label: { type: 'string' },
140
+ type: { type: 'string', enum: FIELD_TYPES },
141
+ required: { type: 'boolean' },
142
+ placeholder: { type: ['string', 'null'] },
143
+ pattern: { type: ['string', 'null'] },
144
+ patternError: { type: ['string', 'null'] },
145
+ autocomplete: { type: ['string', 'null'] },
146
+ inputMode: { type: ['string', 'null'], enum: [...INPUT_MODES, null] },
147
+ pii: { type: ['boolean', 'null'] },
148
+ sensitive: { type: ['boolean', 'null'] },
149
+ helpText: { type: ['string', 'null'] },
150
+ maxLength: { type: ['integer', 'null'] },
151
+ rows: { type: ['integer', 'null'] },
152
+ min: { type: ['number', 'null'] },
153
+ max: { type: ['number', 'null'] },
154
+ options: {
155
+ type: ['array', 'null'],
156
+ items: {
157
+ type: 'object',
158
+ additionalProperties: false,
159
+ required: ['value', 'label'],
160
+ properties: {
161
+ value: { type: 'string' },
162
+ label: { type: 'string' },
163
+ },
164
+ },
165
+ },
166
+ condition: conditionSchema,
167
+ },
168
+ };
169
+
170
+ const sectionSchema = {
171
+ type: 'object',
172
+ additionalProperties: false,
173
+ required: ['id', 'label', 'fields', 'condition'],
174
+ properties: {
175
+ id: { type: 'string' },
176
+ label: { type: 'string' },
177
+ fields: { type: 'array', items: fieldSchema },
178
+ condition: conditionSchema,
179
+ },
180
+ };
181
+
182
+ return {
183
+ type: 'object',
184
+ additionalProperties: false,
185
+ required: ['branches', 'sections'],
186
+ properties: {
187
+ branches: { type: ['array', 'null'], items: { type: 'string' } },
188
+ sections: { type: 'array', items: sectionSchema },
189
+ },
190
+ };
191
+ }