@contractspec/lib.knowledge 2.3.0 → 2.5.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 (44) hide show
  1. package/dist/access/guard.d.ts +3 -0
  2. package/dist/access/guard.js +290 -5
  3. package/dist/access/index.js +290 -5
  4. package/dist/i18n/catalogs/en.d.ts +8 -0
  5. package/dist/i18n/catalogs/en.js +107 -0
  6. package/dist/i18n/catalogs/es.d.ts +6 -0
  7. package/dist/i18n/catalogs/es.js +80 -0
  8. package/dist/i18n/catalogs/fr.d.ts +6 -0
  9. package/dist/i18n/catalogs/fr.js +80 -0
  10. package/dist/i18n/catalogs/index.d.ts +8 -0
  11. package/dist/i18n/catalogs/index.js +263 -0
  12. package/dist/i18n/i18n.test.d.ts +1 -0
  13. package/dist/i18n/index.d.ts +27 -0
  14. package/dist/i18n/index.js +321 -0
  15. package/dist/i18n/keys.d.ts +74 -0
  16. package/dist/i18n/keys.js +33 -0
  17. package/dist/i18n/locale.d.ts +8 -0
  18. package/dist/i18n/locale.js +14 -0
  19. package/dist/i18n/messages.d.ts +14 -0
  20. package/dist/i18n/messages.js +275 -0
  21. package/dist/index.js +316 -23
  22. package/dist/ingestion/gmail-adapter.d.ts +2 -1
  23. package/dist/ingestion/gmail-adapter.js +284 -8
  24. package/dist/ingestion/index.js +284 -8
  25. package/dist/node/access/guard.js +290 -5
  26. package/dist/node/access/index.js +290 -5
  27. package/dist/node/i18n/catalogs/en.js +106 -0
  28. package/dist/node/i18n/catalogs/es.js +79 -0
  29. package/dist/node/i18n/catalogs/fr.js +79 -0
  30. package/dist/node/i18n/catalogs/index.js +262 -0
  31. package/dist/node/i18n/index.js +320 -0
  32. package/dist/node/i18n/keys.js +32 -0
  33. package/dist/node/i18n/locale.js +13 -0
  34. package/dist/node/i18n/messages.js +274 -0
  35. package/dist/node/index.js +316 -23
  36. package/dist/node/ingestion/gmail-adapter.js +284 -8
  37. package/dist/node/ingestion/index.js +284 -8
  38. package/dist/node/query/index.js +282 -10
  39. package/dist/node/query/service.js +282 -10
  40. package/dist/query/index.js +282 -10
  41. package/dist/query/service.d.ts +3 -0
  42. package/dist/query/service.js +282 -10
  43. package/dist/types.d.ts +2 -0
  44. package/package.json +125 -5
@@ -1,15 +1,287 @@
1
1
  // @bun
2
+ // src/i18n/catalogs/en.ts
3
+ import { defineTranslation } from "@contractspec/lib.contracts-spec/translations";
4
+ var enMessages = defineTranslation({
5
+ meta: {
6
+ key: "knowledge.messages",
7
+ version: "1.0.0",
8
+ domain: "knowledge",
9
+ description: "All user-facing and LLM-facing strings for the knowledge package",
10
+ owners: ["platform"],
11
+ stability: "experimental"
12
+ },
13
+ locale: "en",
14
+ fallback: "en",
15
+ messages: {
16
+ "access.notBound": {
17
+ value: 'Knowledge space "{spaceKey}" is not bound in the resolved app config.',
18
+ description: "Denial reason when a knowledge space is not bound",
19
+ placeholders: [{ name: "spaceKey", type: "string" }]
20
+ },
21
+ "access.readOnly": {
22
+ value: 'Knowledge space "{spaceKey}" is category "{category}" and is read-only.',
23
+ description: "Denial reason when write is attempted on a read-only space",
24
+ placeholders: [
25
+ { name: "spaceKey", type: "string" },
26
+ { name: "category", type: "string" }
27
+ ]
28
+ },
29
+ "access.workflowUnauthorized": {
30
+ value: 'Workflow "{workflowName}" is not authorized to access knowledge space "{spaceKey}".',
31
+ description: "Denial reason when a workflow lacks space access",
32
+ placeholders: [
33
+ { name: "workflowName", type: "string" },
34
+ { name: "spaceKey", type: "string" }
35
+ ]
36
+ },
37
+ "access.agentUnauthorized": {
38
+ value: 'Agent "{agentName}" is not authorized to access knowledge space "{spaceKey}".',
39
+ description: "Denial reason when an agent lacks space access",
40
+ placeholders: [
41
+ { name: "agentName", type: "string" },
42
+ { name: "spaceKey", type: "string" }
43
+ ]
44
+ },
45
+ "access.ephemeralWarning": {
46
+ value: 'Knowledge space "{spaceKey}" is ephemeral; results may be transient.',
47
+ description: "Warning for ephemeral knowledge spaces",
48
+ placeholders: [{ name: "spaceKey", type: "string" }]
49
+ },
50
+ "query.systemPrompt": {
51
+ value: "You are a knowledge assistant that answers questions using the provided context. Cite relevant sources if possible.",
52
+ description: "Default LLM system prompt for knowledge queries"
53
+ },
54
+ "query.userMessage": {
55
+ value: `Question:
56
+ {question}
57
+
58
+ Context:
59
+ {context}`,
60
+ description: "User message template combining question and context",
61
+ placeholders: [
62
+ { name: "question", type: "string" },
63
+ { name: "context", type: "string" }
64
+ ]
65
+ },
66
+ "query.noResults": {
67
+ value: "No relevant documents found.",
68
+ description: "Displayed when vector search returns zero results"
69
+ },
70
+ "query.sourceLabel": {
71
+ value: "Source {index} (score: {score}):",
72
+ description: "Label prefix for each source in the context block",
73
+ placeholders: [
74
+ { name: "index", type: "number" },
75
+ { name: "score", type: "string" }
76
+ ]
77
+ },
78
+ "ingestion.gmail.subject": {
79
+ value: "Subject: {subject}",
80
+ description: "Gmail thread subject label",
81
+ placeholders: [{ name: "subject", type: "string" }]
82
+ },
83
+ "ingestion.gmail.snippet": {
84
+ value: "Snippet: {snippet}",
85
+ description: "Gmail thread snippet label",
86
+ placeholders: [{ name: "snippet", type: "string" }]
87
+ },
88
+ "ingestion.gmail.from": {
89
+ value: "From: {from}",
90
+ description: "Gmail message sender label",
91
+ placeholders: [{ name: "from", type: "string" }]
92
+ },
93
+ "ingestion.gmail.to": {
94
+ value: "To: {to}",
95
+ description: "Gmail message recipients label",
96
+ placeholders: [{ name: "to", type: "string" }]
97
+ },
98
+ "ingestion.gmail.date": {
99
+ value: "Date: {date}",
100
+ description: "Gmail message date label",
101
+ placeholders: [{ name: "date", type: "string" }]
102
+ }
103
+ }
104
+ });
105
+
106
+ // src/i18n/catalogs/fr.ts
107
+ import { defineTranslation as defineTranslation2 } from "@contractspec/lib.contracts-spec/translations";
108
+ var frMessages = defineTranslation2({
109
+ meta: {
110
+ key: "knowledge.messages",
111
+ version: "1.0.0",
112
+ domain: "knowledge",
113
+ description: "All user-facing and LLM-facing strings for the knowledge package (French)",
114
+ owners: ["platform"],
115
+ stability: "experimental"
116
+ },
117
+ locale: "fr",
118
+ fallback: "en",
119
+ messages: {
120
+ "access.notBound": {
121
+ value: `L'espace de connaissances "{spaceKey}" n'est pas li\xE9 dans la configuration de l'application.`,
122
+ description: "Denial reason when a knowledge space is not bound"
123
+ },
124
+ "access.readOnly": {
125
+ value: `L'espace de connaissances "{spaceKey}" est de cat\xE9gorie "{category}" et est en lecture seule.`,
126
+ description: "Denial reason when write is attempted on a read-only space"
127
+ },
128
+ "access.workflowUnauthorized": {
129
+ value: `Le workflow "{workflowName}" n'est pas autoris\xE9 \xE0 acc\xE9der \xE0 l'espace de connaissances "{spaceKey}".`,
130
+ description: "Denial reason when a workflow lacks space access"
131
+ },
132
+ "access.agentUnauthorized": {
133
+ value: `L'agent "{agentName}" n'est pas autoris\xE9 \xE0 acc\xE9der \xE0 l'espace de connaissances "{spaceKey}".`,
134
+ description: "Denial reason when an agent lacks space access"
135
+ },
136
+ "access.ephemeralWarning": {
137
+ value: `L'espace de connaissances "{spaceKey}" est \xE9ph\xE9m\xE8re ; les r\xE9sultats peuvent \xEAtre transitoires.`,
138
+ description: "Warning for ephemeral knowledge spaces"
139
+ },
140
+ "query.systemPrompt": {
141
+ value: "Vous \xEAtes un assistant de connaissances qui r\xE9pond aux questions en utilisant le contexte fourni. Citez les sources pertinentes si possible.",
142
+ description: "Default LLM system prompt for knowledge queries"
143
+ },
144
+ "query.userMessage": {
145
+ value: `Question :
146
+ {question}
147
+
148
+ Contexte :
149
+ {context}`,
150
+ description: "User message template combining question and context"
151
+ },
152
+ "query.noResults": {
153
+ value: "Aucun document pertinent trouv\xE9.",
154
+ description: "Displayed when vector search returns zero results"
155
+ },
156
+ "query.sourceLabel": {
157
+ value: "Source {index} (score : {score}) :",
158
+ description: "Label prefix for each source in the context block"
159
+ },
160
+ "ingestion.gmail.subject": {
161
+ value: "Objet : {subject}",
162
+ description: "Gmail thread subject label"
163
+ },
164
+ "ingestion.gmail.snippet": {
165
+ value: "Extrait : {snippet}",
166
+ description: "Gmail thread snippet label"
167
+ },
168
+ "ingestion.gmail.from": {
169
+ value: "De : {from}",
170
+ description: "Gmail message sender label"
171
+ },
172
+ "ingestion.gmail.to": {
173
+ value: "\xC0 : {to}",
174
+ description: "Gmail message recipients label"
175
+ },
176
+ "ingestion.gmail.date": {
177
+ value: "Date : {date}",
178
+ description: "Gmail message date label"
179
+ }
180
+ }
181
+ });
182
+
183
+ // src/i18n/catalogs/es.ts
184
+ import { defineTranslation as defineTranslation3 } from "@contractspec/lib.contracts-spec/translations";
185
+ var esMessages = defineTranslation3({
186
+ meta: {
187
+ key: "knowledge.messages",
188
+ version: "1.0.0",
189
+ domain: "knowledge",
190
+ description: "All user-facing and LLM-facing strings for the knowledge package (Spanish)",
191
+ owners: ["platform"],
192
+ stability: "experimental"
193
+ },
194
+ locale: "es",
195
+ fallback: "en",
196
+ messages: {
197
+ "access.notBound": {
198
+ value: 'El espacio de conocimiento "{spaceKey}" no est\xE1 vinculado en la configuraci\xF3n de la aplicaci\xF3n.',
199
+ description: "Denial reason when a knowledge space is not bound"
200
+ },
201
+ "access.readOnly": {
202
+ value: 'El espacio de conocimiento "{spaceKey}" es de categor\xEDa "{category}" y es de solo lectura.',
203
+ description: "Denial reason when write is attempted on a read-only space"
204
+ },
205
+ "access.workflowUnauthorized": {
206
+ value: 'El flujo de trabajo "{workflowName}" no est\xE1 autorizado para acceder al espacio de conocimiento "{spaceKey}".',
207
+ description: "Denial reason when a workflow lacks space access"
208
+ },
209
+ "access.agentUnauthorized": {
210
+ value: 'El agente "{agentName}" no est\xE1 autorizado para acceder al espacio de conocimiento "{spaceKey}".',
211
+ description: "Denial reason when an agent lacks space access"
212
+ },
213
+ "access.ephemeralWarning": {
214
+ value: 'El espacio de conocimiento "{spaceKey}" es ef\xEDmero; los resultados pueden ser transitorios.',
215
+ description: "Warning for ephemeral knowledge spaces"
216
+ },
217
+ "query.systemPrompt": {
218
+ value: "Eres un asistente de conocimiento que responde preguntas utilizando el contexto proporcionado. Cita las fuentes relevantes si es posible.",
219
+ description: "Default LLM system prompt for knowledge queries"
220
+ },
221
+ "query.userMessage": {
222
+ value: `Pregunta:
223
+ {question}
224
+
225
+ Contexto:
226
+ {context}`,
227
+ description: "User message template combining question and context"
228
+ },
229
+ "query.noResults": {
230
+ value: "No se encontraron documentos relevantes.",
231
+ description: "Displayed when vector search returns zero results"
232
+ },
233
+ "query.sourceLabel": {
234
+ value: "Fuente {index} (puntuaci\xF3n: {score}):",
235
+ description: "Label prefix for each source in the context block"
236
+ },
237
+ "ingestion.gmail.subject": {
238
+ value: "Asunto: {subject}",
239
+ description: "Gmail thread subject label"
240
+ },
241
+ "ingestion.gmail.snippet": {
242
+ value: "Extracto: {snippet}",
243
+ description: "Gmail thread snippet label"
244
+ },
245
+ "ingestion.gmail.from": {
246
+ value: "De: {from}",
247
+ description: "Gmail message sender label"
248
+ },
249
+ "ingestion.gmail.to": {
250
+ value: "Para: {to}",
251
+ description: "Gmail message recipients label"
252
+ },
253
+ "ingestion.gmail.date": {
254
+ value: "Fecha: {date}",
255
+ description: "Gmail message date label"
256
+ }
257
+ }
258
+ });
259
+
260
+ // src/i18n/messages.ts
261
+ import {
262
+ createI18nFactory
263
+ } from "@contractspec/lib.contracts-spec/translations";
264
+ var factory = createI18nFactory({
265
+ specKey: "knowledge.messages",
266
+ catalogs: [enMessages, frMessages, esMessages]
267
+ });
268
+ var createKnowledgeI18n = factory.create;
269
+ var getDefaultI18n = factory.getDefault;
270
+ var resetI18nRegistry = factory.resetRegistry;
271
+
2
272
  // src/ingestion/gmail-adapter.ts
3
273
  class GmailIngestionAdapter {
4
274
  gmail;
5
275
  processor;
6
276
  embeddings;
7
277
  indexer;
8
- constructor(gmail, processor, embeddings, indexer) {
278
+ i18n;
279
+ constructor(gmail, processor, embeddings, indexer, locale) {
9
280
  this.gmail = gmail;
10
281
  this.processor = processor;
11
282
  this.embeddings = embeddings;
12
283
  this.indexer = indexer;
284
+ this.i18n = locale ? createKnowledgeI18n(locale) : getDefaultI18n();
13
285
  }
14
286
  async syncThreads(query) {
15
287
  const threads = await this.gmail.listThreads(query);
@@ -24,7 +296,7 @@ class GmailIngestionAdapter {
24
296
  await this.indexer.upsert(fragments, embeddings);
25
297
  }
26
298
  toRawDocument(thread) {
27
- const content = composeThreadText(thread);
299
+ const content = composeThreadText(thread, this.i18n);
28
300
  return {
29
301
  id: thread.id,
30
302
  mimeType: "text/plain",
@@ -37,18 +309,22 @@ class GmailIngestionAdapter {
37
309
  };
38
310
  }
39
311
  }
40
- function composeThreadText(thread) {
312
+ function composeThreadText(thread, i18n) {
41
313
  const header = [
42
- `Subject: ${thread.subject ?? ""}`,
43
- `Snippet: ${thread.snippet ?? ""}`
314
+ i18n.t("ingestion.gmail.subject", { subject: thread.subject ?? "" }),
315
+ i18n.t("ingestion.gmail.snippet", { snippet: thread.snippet ?? "" })
44
316
  ];
45
317
  const messageTexts = thread.messages.map((message) => {
46
318
  const parts = [
47
- `From: ${formatAddress(message.from)}`,
48
- `To: ${message.to.map(formatAddress).join(", ")}`
319
+ i18n.t("ingestion.gmail.from", { from: formatAddress(message.from) }),
320
+ i18n.t("ingestion.gmail.to", {
321
+ to: message.to.map(formatAddress).join(", ")
322
+ })
49
323
  ];
50
324
  if (message.sentAt) {
51
- parts.push(`Date: ${message.sentAt.toISOString()}`);
325
+ parts.push(i18n.t("ingestion.gmail.date", {
326
+ date: message.sentAt.toISOString()
327
+ }));
52
328
  }
53
329
  const body = message.textBody ?? stripHtml(message.htmlBody ?? "");
54
330
  return `${parts.join(`
@@ -1,4 +1,274 @@
1
1
  // @bun
2
+ // src/i18n/catalogs/en.ts
3
+ import { defineTranslation } from "@contractspec/lib.contracts-spec/translations";
4
+ var enMessages = defineTranslation({
5
+ meta: {
6
+ key: "knowledge.messages",
7
+ version: "1.0.0",
8
+ domain: "knowledge",
9
+ description: "All user-facing and LLM-facing strings for the knowledge package",
10
+ owners: ["platform"],
11
+ stability: "experimental"
12
+ },
13
+ locale: "en",
14
+ fallback: "en",
15
+ messages: {
16
+ "access.notBound": {
17
+ value: 'Knowledge space "{spaceKey}" is not bound in the resolved app config.',
18
+ description: "Denial reason when a knowledge space is not bound",
19
+ placeholders: [{ name: "spaceKey", type: "string" }]
20
+ },
21
+ "access.readOnly": {
22
+ value: 'Knowledge space "{spaceKey}" is category "{category}" and is read-only.',
23
+ description: "Denial reason when write is attempted on a read-only space",
24
+ placeholders: [
25
+ { name: "spaceKey", type: "string" },
26
+ { name: "category", type: "string" }
27
+ ]
28
+ },
29
+ "access.workflowUnauthorized": {
30
+ value: 'Workflow "{workflowName}" is not authorized to access knowledge space "{spaceKey}".',
31
+ description: "Denial reason when a workflow lacks space access",
32
+ placeholders: [
33
+ { name: "workflowName", type: "string" },
34
+ { name: "spaceKey", type: "string" }
35
+ ]
36
+ },
37
+ "access.agentUnauthorized": {
38
+ value: 'Agent "{agentName}" is not authorized to access knowledge space "{spaceKey}".',
39
+ description: "Denial reason when an agent lacks space access",
40
+ placeholders: [
41
+ { name: "agentName", type: "string" },
42
+ { name: "spaceKey", type: "string" }
43
+ ]
44
+ },
45
+ "access.ephemeralWarning": {
46
+ value: 'Knowledge space "{spaceKey}" is ephemeral; results may be transient.',
47
+ description: "Warning for ephemeral knowledge spaces",
48
+ placeholders: [{ name: "spaceKey", type: "string" }]
49
+ },
50
+ "query.systemPrompt": {
51
+ value: "You are a knowledge assistant that answers questions using the provided context. Cite relevant sources if possible.",
52
+ description: "Default LLM system prompt for knowledge queries"
53
+ },
54
+ "query.userMessage": {
55
+ value: `Question:
56
+ {question}
57
+
58
+ Context:
59
+ {context}`,
60
+ description: "User message template combining question and context",
61
+ placeholders: [
62
+ { name: "question", type: "string" },
63
+ { name: "context", type: "string" }
64
+ ]
65
+ },
66
+ "query.noResults": {
67
+ value: "No relevant documents found.",
68
+ description: "Displayed when vector search returns zero results"
69
+ },
70
+ "query.sourceLabel": {
71
+ value: "Source {index} (score: {score}):",
72
+ description: "Label prefix for each source in the context block",
73
+ placeholders: [
74
+ { name: "index", type: "number" },
75
+ { name: "score", type: "string" }
76
+ ]
77
+ },
78
+ "ingestion.gmail.subject": {
79
+ value: "Subject: {subject}",
80
+ description: "Gmail thread subject label",
81
+ placeholders: [{ name: "subject", type: "string" }]
82
+ },
83
+ "ingestion.gmail.snippet": {
84
+ value: "Snippet: {snippet}",
85
+ description: "Gmail thread snippet label",
86
+ placeholders: [{ name: "snippet", type: "string" }]
87
+ },
88
+ "ingestion.gmail.from": {
89
+ value: "From: {from}",
90
+ description: "Gmail message sender label",
91
+ placeholders: [{ name: "from", type: "string" }]
92
+ },
93
+ "ingestion.gmail.to": {
94
+ value: "To: {to}",
95
+ description: "Gmail message recipients label",
96
+ placeholders: [{ name: "to", type: "string" }]
97
+ },
98
+ "ingestion.gmail.date": {
99
+ value: "Date: {date}",
100
+ description: "Gmail message date label",
101
+ placeholders: [{ name: "date", type: "string" }]
102
+ }
103
+ }
104
+ });
105
+
106
+ // src/i18n/catalogs/fr.ts
107
+ import { defineTranslation as defineTranslation2 } from "@contractspec/lib.contracts-spec/translations";
108
+ var frMessages = defineTranslation2({
109
+ meta: {
110
+ key: "knowledge.messages",
111
+ version: "1.0.0",
112
+ domain: "knowledge",
113
+ description: "All user-facing and LLM-facing strings for the knowledge package (French)",
114
+ owners: ["platform"],
115
+ stability: "experimental"
116
+ },
117
+ locale: "fr",
118
+ fallback: "en",
119
+ messages: {
120
+ "access.notBound": {
121
+ value: `L'espace de connaissances "{spaceKey}" n'est pas li\xE9 dans la configuration de l'application.`,
122
+ description: "Denial reason when a knowledge space is not bound"
123
+ },
124
+ "access.readOnly": {
125
+ value: `L'espace de connaissances "{spaceKey}" est de cat\xE9gorie "{category}" et est en lecture seule.`,
126
+ description: "Denial reason when write is attempted on a read-only space"
127
+ },
128
+ "access.workflowUnauthorized": {
129
+ value: `Le workflow "{workflowName}" n'est pas autoris\xE9 \xE0 acc\xE9der \xE0 l'espace de connaissances "{spaceKey}".`,
130
+ description: "Denial reason when a workflow lacks space access"
131
+ },
132
+ "access.agentUnauthorized": {
133
+ value: `L'agent "{agentName}" n'est pas autoris\xE9 \xE0 acc\xE9der \xE0 l'espace de connaissances "{spaceKey}".`,
134
+ description: "Denial reason when an agent lacks space access"
135
+ },
136
+ "access.ephemeralWarning": {
137
+ value: `L'espace de connaissances "{spaceKey}" est \xE9ph\xE9m\xE8re ; les r\xE9sultats peuvent \xEAtre transitoires.`,
138
+ description: "Warning for ephemeral knowledge spaces"
139
+ },
140
+ "query.systemPrompt": {
141
+ value: "Vous \xEAtes un assistant de connaissances qui r\xE9pond aux questions en utilisant le contexte fourni. Citez les sources pertinentes si possible.",
142
+ description: "Default LLM system prompt for knowledge queries"
143
+ },
144
+ "query.userMessage": {
145
+ value: `Question :
146
+ {question}
147
+
148
+ Contexte :
149
+ {context}`,
150
+ description: "User message template combining question and context"
151
+ },
152
+ "query.noResults": {
153
+ value: "Aucun document pertinent trouv\xE9.",
154
+ description: "Displayed when vector search returns zero results"
155
+ },
156
+ "query.sourceLabel": {
157
+ value: "Source {index} (score : {score}) :",
158
+ description: "Label prefix for each source in the context block"
159
+ },
160
+ "ingestion.gmail.subject": {
161
+ value: "Objet : {subject}",
162
+ description: "Gmail thread subject label"
163
+ },
164
+ "ingestion.gmail.snippet": {
165
+ value: "Extrait : {snippet}",
166
+ description: "Gmail thread snippet label"
167
+ },
168
+ "ingestion.gmail.from": {
169
+ value: "De : {from}",
170
+ description: "Gmail message sender label"
171
+ },
172
+ "ingestion.gmail.to": {
173
+ value: "\xC0 : {to}",
174
+ description: "Gmail message recipients label"
175
+ },
176
+ "ingestion.gmail.date": {
177
+ value: "Date : {date}",
178
+ description: "Gmail message date label"
179
+ }
180
+ }
181
+ });
182
+
183
+ // src/i18n/catalogs/es.ts
184
+ import { defineTranslation as defineTranslation3 } from "@contractspec/lib.contracts-spec/translations";
185
+ var esMessages = defineTranslation3({
186
+ meta: {
187
+ key: "knowledge.messages",
188
+ version: "1.0.0",
189
+ domain: "knowledge",
190
+ description: "All user-facing and LLM-facing strings for the knowledge package (Spanish)",
191
+ owners: ["platform"],
192
+ stability: "experimental"
193
+ },
194
+ locale: "es",
195
+ fallback: "en",
196
+ messages: {
197
+ "access.notBound": {
198
+ value: 'El espacio de conocimiento "{spaceKey}" no est\xE1 vinculado en la configuraci\xF3n de la aplicaci\xF3n.',
199
+ description: "Denial reason when a knowledge space is not bound"
200
+ },
201
+ "access.readOnly": {
202
+ value: 'El espacio de conocimiento "{spaceKey}" es de categor\xEDa "{category}" y es de solo lectura.',
203
+ description: "Denial reason when write is attempted on a read-only space"
204
+ },
205
+ "access.workflowUnauthorized": {
206
+ value: 'El flujo de trabajo "{workflowName}" no est\xE1 autorizado para acceder al espacio de conocimiento "{spaceKey}".',
207
+ description: "Denial reason when a workflow lacks space access"
208
+ },
209
+ "access.agentUnauthorized": {
210
+ value: 'El agente "{agentName}" no est\xE1 autorizado para acceder al espacio de conocimiento "{spaceKey}".',
211
+ description: "Denial reason when an agent lacks space access"
212
+ },
213
+ "access.ephemeralWarning": {
214
+ value: 'El espacio de conocimiento "{spaceKey}" es ef\xEDmero; los resultados pueden ser transitorios.',
215
+ description: "Warning for ephemeral knowledge spaces"
216
+ },
217
+ "query.systemPrompt": {
218
+ value: "Eres un asistente de conocimiento que responde preguntas utilizando el contexto proporcionado. Cita las fuentes relevantes si es posible.",
219
+ description: "Default LLM system prompt for knowledge queries"
220
+ },
221
+ "query.userMessage": {
222
+ value: `Pregunta:
223
+ {question}
224
+
225
+ Contexto:
226
+ {context}`,
227
+ description: "User message template combining question and context"
228
+ },
229
+ "query.noResults": {
230
+ value: "No se encontraron documentos relevantes.",
231
+ description: "Displayed when vector search returns zero results"
232
+ },
233
+ "query.sourceLabel": {
234
+ value: "Fuente {index} (puntuaci\xF3n: {score}):",
235
+ description: "Label prefix for each source in the context block"
236
+ },
237
+ "ingestion.gmail.subject": {
238
+ value: "Asunto: {subject}",
239
+ description: "Gmail thread subject label"
240
+ },
241
+ "ingestion.gmail.snippet": {
242
+ value: "Extracto: {snippet}",
243
+ description: "Gmail thread snippet label"
244
+ },
245
+ "ingestion.gmail.from": {
246
+ value: "De: {from}",
247
+ description: "Gmail message sender label"
248
+ },
249
+ "ingestion.gmail.to": {
250
+ value: "Para: {to}",
251
+ description: "Gmail message recipients label"
252
+ },
253
+ "ingestion.gmail.date": {
254
+ value: "Fecha: {date}",
255
+ description: "Gmail message date label"
256
+ }
257
+ }
258
+ });
259
+
260
+ // src/i18n/messages.ts
261
+ import {
262
+ createI18nFactory
263
+ } from "@contractspec/lib.contracts-spec/translations";
264
+ var factory = createI18nFactory({
265
+ specKey: "knowledge.messages",
266
+ catalogs: [enMessages, frMessages, esMessages]
267
+ });
268
+ var createKnowledgeI18n = factory.create;
269
+ var getDefaultI18n = factory.getDefault;
270
+ var resetI18nRegistry = factory.resetRegistry;
271
+
2
272
  // src/ingestion/document-processor.ts
3
273
  import { Buffer as Buffer2 } from "buffer";
4
274
 
@@ -121,11 +391,13 @@ class GmailIngestionAdapter {
121
391
  processor;
122
392
  embeddings;
123
393
  indexer;
124
- constructor(gmail, processor, embeddings, indexer) {
394
+ i18n;
395
+ constructor(gmail, processor, embeddings, indexer, locale) {
125
396
  this.gmail = gmail;
126
397
  this.processor = processor;
127
398
  this.embeddings = embeddings;
128
399
  this.indexer = indexer;
400
+ this.i18n = locale ? createKnowledgeI18n(locale) : getDefaultI18n();
129
401
  }
130
402
  async syncThreads(query) {
131
403
  const threads = await this.gmail.listThreads(query);
@@ -140,7 +412,7 @@ class GmailIngestionAdapter {
140
412
  await this.indexer.upsert(fragments, embeddings);
141
413
  }
142
414
  toRawDocument(thread) {
143
- const content = composeThreadText(thread);
415
+ const content = composeThreadText(thread, this.i18n);
144
416
  return {
145
417
  id: thread.id,
146
418
  mimeType: "text/plain",
@@ -153,18 +425,22 @@ class GmailIngestionAdapter {
153
425
  };
154
426
  }
155
427
  }
156
- function composeThreadText(thread) {
428
+ function composeThreadText(thread, i18n) {
157
429
  const header = [
158
- `Subject: ${thread.subject ?? ""}`,
159
- `Snippet: ${thread.snippet ?? ""}`
430
+ i18n.t("ingestion.gmail.subject", { subject: thread.subject ?? "" }),
431
+ i18n.t("ingestion.gmail.snippet", { snippet: thread.snippet ?? "" })
160
432
  ];
161
433
  const messageTexts = thread.messages.map((message) => {
162
434
  const parts = [
163
- `From: ${formatAddress(message.from)}`,
164
- `To: ${message.to.map(formatAddress).join(", ")}`
435
+ i18n.t("ingestion.gmail.from", { from: formatAddress(message.from) }),
436
+ i18n.t("ingestion.gmail.to", {
437
+ to: message.to.map(formatAddress).join(", ")
438
+ })
165
439
  ];
166
440
  if (message.sentAt) {
167
- parts.push(`Date: ${message.sentAt.toISOString()}`);
441
+ parts.push(i18n.t("ingestion.gmail.date", {
442
+ date: message.sentAt.toISOString()
443
+ }));
168
444
  }
169
445
  const body = message.textBody ?? stripHtml(message.htmlBody ?? "");
170
446
  return `${parts.join(`