@lssm/lib.contracts 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406
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/dist/app-config/app-config.feature.js +53 -1
- package/dist/app-config/contracts.d.ts +50 -50
- package/dist/app-config/contracts.js +396 -1
- package/dist/app-config/docs/app-config.docblock.js +22 -220
- package/dist/app-config/events.js +168 -1
- package/dist/app-config/index.js +8 -1
- package/dist/app-config/lifecycle-contracts.js +441 -1
- package/dist/app-config/runtime.js +617 -1
- package/dist/app-config/spec.js +36 -1
- package/dist/app-config/validation.js +538 -1
- package/dist/capabilities/docs/capabilities.docblock.js +22 -1
- package/dist/capabilities/openbanking.js +92 -1
- package/dist/capabilities.js +50 -1
- package/dist/client/index.js +9 -1
- package/dist/client/react/drivers/rn-reusables.js +21 -1
- package/dist/client/react/drivers/shadcn.js +11 -1
- package/dist/client/react/feature-render.js +43 -1
- package/dist/client/react/form-render.js +298 -1
- package/dist/client/react/index.js +8 -1
- package/dist/contract-registry/index.js +3 -1
- package/dist/contract-registry/schemas.js +61 -1
- package/dist/contracts-adapter-hydration.js +41 -1
- package/dist/contracts-adapter-input.js +77 -1
- package/dist/data-views/docs/data-views.docblock.js +22 -1
- package/dist/data-views/query-generator.js +48 -1
- package/dist/data-views/runtime.js +39 -1
- package/dist/data-views.js +35 -1
- package/dist/docs/PUBLISHING.docblock.js +17 -76
- package/dist/docs/accessibility_wcag_compliance_specs.docblock.js +17 -350
- package/dist/docs/index.js +33 -1
- package/dist/docs/meta.docs.js +15 -2
- package/dist/docs/presentations.js +77 -1
- package/dist/docs/registry.js +51 -1
- package/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +17 -383
- package/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +17 -68
- package/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +17 -140
- package/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +17 -86
- package/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +17 -1
- package/dist/docs/tech/auth/better-auth-nextjs.docblock.js +25 -2
- package/dist/docs/tech/contracts/README.docblock.js +21 -1
- package/dist/docs/tech/contracts/create-subscription.docblock.js +21 -1
- package/dist/docs/tech/contracts/graphql-typed-outputs.docblock.js +21 -180
- package/dist/docs/tech/contracts/migrations.docblock.js +21 -1
- package/dist/docs/tech/contracts/openapi-export.docblock.js +22 -2
- package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +19 -60
- package/dist/docs/tech/contracts/overlays.docblock.js +21 -68
- package/dist/docs/tech/contracts/tests.docblock.js +21 -132
- package/dist/docs/tech/contracts/themes.docblock.js +21 -1
- package/dist/docs/tech/contracts/vertical-pocket-family-office.docblock.js +21 -106
- package/dist/docs/tech/lifecycle-stage-system.docblock.js +17 -213
- package/dist/docs/tech/llm/llm-integration.docblock.js +74 -5
- package/dist/docs/tech/mcp-endpoints.docblock.js +38 -1
- package/dist/docs/tech/presentation-runtime.docblock.js +17 -1
- package/dist/docs/tech/schema/README.docblock.js +21 -262
- package/dist/docs/tech/studio/learning-events.docblock.js +49 -1
- package/dist/docs/tech/studio/learning-journeys.docblock.js +25 -2
- package/dist/docs/tech/studio/platform-admin-panel.docblock.js +24 -2
- package/dist/docs/tech/studio/project-access-teams.docblock.js +26 -16
- package/dist/docs/tech/studio/project-routing.docblock.js +68 -1
- package/dist/docs/tech/studio/sandbox-unlogged.docblock.js +23 -2
- package/dist/docs/tech/studio/team-invitations.docblock.js +41 -36
- package/dist/docs/tech/studio/workspace-ops.docblock.js +48 -1
- package/dist/docs/tech/studio/workspaces.docblock.js +24 -2
- package/dist/docs/tech/telemetry-ingest.docblock.js +37 -3
- package/dist/docs/tech/templates/runtime.docblock.js +21 -1
- package/dist/docs/tech/vscode-extension.docblock.js +37 -3
- package/dist/docs/tech/workflows/overview.docblock.js +21 -1
- package/dist/docs/tech-contracts.docs.js +19 -2
- package/dist/events.js +12 -1
- package/dist/experiments/docs/experiments.docblock.js +22 -128
- package/dist/experiments/evaluator.js +101 -1
- package/dist/experiments/spec.js +33 -1
- package/dist/features.js +68 -1
- package/dist/forms/docs/forms.docblock.js +22 -1
- package/dist/forms.js +119 -1
- package/dist/index.js +107 -1
- package/dist/install.js +40 -1
- package/dist/integrations/contracts.d.ts +102 -102
- package/dist/integrations/contracts.js +388 -1
- package/dist/integrations/docs/integrations.docblock.js +95 -1
- package/dist/integrations/health.js +69 -1
- package/dist/integrations/index.js +23 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
- package/dist/integrations/openbanking/contracts/accounts.js +237 -1
- package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
- package/dist/integrations/openbanking/contracts/balances.js +167 -1
- package/dist/integrations/openbanking/contracts/index.js +12 -1
- package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
- package/dist/integrations/openbanking/contracts/transactions.js +218 -1
- package/dist/integrations/openbanking/guards.js +32 -1
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/openbanking/models.js +242 -1
- package/dist/integrations/openbanking/openbanking.feature.js +68 -1
- package/dist/integrations/openbanking/telemetry.js +39 -1
- package/dist/integrations/providers/elevenlabs.js +56 -1
- package/dist/integrations/providers/gcs-storage.js +79 -1
- package/dist/integrations/providers/gmail.js +91 -1
- package/dist/integrations/providers/google-calendar.js +70 -1
- package/dist/integrations/providers/impls/elevenlabs-voice.js +95 -1
- package/dist/integrations/providers/impls/gcs-storage.js +88 -1
- package/dist/integrations/providers/impls/gmail-inbound.js +200 -1
- package/dist/integrations/providers/impls/gmail-outbound.js +104 -5
- package/dist/integrations/providers/impls/google-calendar.js +154 -1
- package/dist/integrations/providers/impls/index.js +16 -1
- package/dist/integrations/providers/impls/mistral-embedding.js +41 -1
- package/dist/integrations/providers/impls/mistral-llm.js +247 -1
- package/dist/integrations/providers/impls/postmark-email.js +55 -1
- package/dist/integrations/providers/impls/powens-client.js +171 -1
- package/dist/integrations/providers/impls/powens-openbanking.js +218 -1
- package/dist/integrations/providers/impls/provider-factory.js +142 -1
- package/dist/integrations/providers/impls/qdrant-vector.js +69 -1
- package/dist/integrations/providers/impls/stripe-payments.js +202 -1
- package/dist/integrations/providers/impls/twilio-sms.js +58 -1
- package/dist/integrations/providers/index.js +13 -1
- package/dist/integrations/providers/mistral.js +72 -1
- package/dist/integrations/providers/postmark.js +72 -1
- package/dist/integrations/providers/powens.js +120 -1
- package/dist/integrations/providers/qdrant.js +77 -1
- package/dist/integrations/providers/registry.js +34 -1
- package/dist/integrations/providers/stripe.js +87 -1
- package/dist/integrations/providers/twilio-sms.js +65 -1
- package/dist/integrations/runtime.js +186 -1
- package/dist/integrations/secrets/aws-secret-manager.js +231 -1
- package/dist/integrations/secrets/env-secret-provider.js +81 -1
- package/dist/integrations/secrets/gcp-secret-manager.js +229 -1
- package/dist/integrations/secrets/index.js +8 -1
- package/dist/integrations/secrets/manager.js +103 -1
- package/dist/integrations/secrets/provider.js +58 -1
- package/dist/integrations/secrets/scaleway-secret-manager.js +247 -1
- package/dist/integrations/spec.js +39 -1
- package/dist/jobs/define-job.js +16 -1
- package/dist/jobs/gcp-cloud-tasks.js +53 -1
- package/dist/jobs/gcp-pubsub.js +39 -1
- package/dist/jobs/handlers/gmail-sync-handler.js +9 -1
- package/dist/jobs/handlers/index.js +12 -1
- package/dist/jobs/handlers/ping-handler.js +15 -1
- package/dist/jobs/handlers/storage-document-handler.js +14 -1
- package/dist/jobs/index.js +4 -1
- package/dist/jobs/memory-queue.js +71 -1
- package/dist/jobs/queue.js +33 -1
- package/dist/jobs/scaleway-sqs-queue.js +153 -1
- package/dist/jsonschema.d.ts +3 -3
- package/dist/jsonschema.js +32 -1
- package/dist/knowledge/contracts.d.ts +66 -66
- package/dist/knowledge/contracts.js +317 -1
- package/dist/knowledge/docs/knowledge.docblock.js +22 -138
- package/dist/knowledge/index.js +10 -1
- package/dist/knowledge/ingestion/document-processor.js +54 -1
- package/dist/knowledge/ingestion/embedding-service.js +25 -1
- package/dist/knowledge/ingestion/gmail-adapter.js +50 -5
- package/dist/knowledge/ingestion/index.js +7 -1
- package/dist/knowledge/ingestion/storage-adapter.js +26 -1
- package/dist/knowledge/ingestion/vector-indexer.js +32 -1
- package/dist/knowledge/query/index.js +3 -1
- package/dist/knowledge/query/service.js +64 -2
- package/dist/knowledge/runtime.js +49 -1
- package/dist/knowledge/spaces/email-threads.js +38 -1
- package/dist/knowledge/spaces/financial-docs.js +38 -1
- package/dist/knowledge/spaces/financial-overview.js +42 -1
- package/dist/knowledge/spaces/index.js +8 -1
- package/dist/knowledge/spaces/product-canon.js +38 -1
- package/dist/knowledge/spaces/support-faq.js +41 -1
- package/dist/knowledge/spaces/uploaded-docs.js +38 -1
- package/dist/knowledge/spec.js +39 -1
- package/dist/llm/exporters.js +541 -8
- package/dist/llm/index.js +4 -1
- package/dist/llm/prompts.js +246 -56
- package/dist/markdown.js +116 -3
- package/dist/migrations.js +33 -1
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/onboarding-base.js +196 -1
- package/dist/openapi.js +75 -1
- package/dist/openbanking/docs/openbanking.docblock.js +22 -109
- package/dist/ownership.js +40 -1
- package/dist/policy/docs/policy.docblock.js +22 -1
- package/dist/policy/engine.js +223 -1
- package/dist/policy/opa-adapter.js +71 -1
- package/dist/policy/spec.js +33 -1
- package/dist/presentations/docs/presentations-conventions.docblock.js +21 -7
- package/dist/presentations.backcompat.js +47 -1
- package/dist/presentations.d.ts +3 -3
- package/dist/presentations.js +66 -1
- package/dist/presentations.v2.js +278 -6
- package/dist/prompt.js +10 -1
- package/dist/promptRegistry.js +34 -1
- package/dist/regenerator/docs/regenerator.docblock.js +22 -184
- package/dist/regenerator/executor.js +86 -1
- package/dist/regenerator/index.js +6 -1
- package/dist/regenerator/service.js +92 -1
- package/dist/regenerator/sinks.js +32 -1
- package/dist/regenerator/utils.js +51 -1
- package/dist/registry.js +208 -1
- package/dist/resources.js +47 -1
- package/dist/schema/dist/EnumType.js +2 -1
- package/dist/schema/dist/FieldType.js +49 -1
- package/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/schema/dist/SchemaModel.js +39 -1
- package/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/schema/dist/entity/index.js +2 -1
- package/dist/schema/dist/entity/types.js +1 -1
- package/dist/schema/dist/index.js +6 -1
- package/dist/schema-to-markdown.js +214 -10
- package/dist/server/graphql-pothos.js +128 -1
- package/dist/server/index.js +10 -1
- package/dist/server/mcp/createMcpServer.js +28 -1
- package/dist/server/mcp/registerPresentations.js +151 -1
- package/dist/server/mcp/registerPrompts.js +36 -2
- package/dist/server/mcp/registerResources.js +35 -1
- package/dist/server/mcp/registerTools.js +22 -1
- package/dist/server/provider-mcp.js +3 -1
- package/dist/server/rest-elysia.js +20 -1
- package/dist/server/rest-express.js +39 -1
- package/dist/server/rest-generic.js +125 -1
- package/dist/server/rest-next-app.js +38 -1
- package/dist/server/rest-next-mcp.js +45 -1
- package/dist/server/rest-next-pages.js +25 -1
- package/dist/spec.js +35 -1
- package/dist/telemetry/anomaly.js +48 -1
- package/dist/telemetry/docs/telemetry.docblock.js +22 -139
- package/dist/telemetry/index.js +5 -1
- package/dist/telemetry/spec.js +69 -1
- package/dist/telemetry/tracker.js +76 -1
- package/dist/tests/index.js +4 -1
- package/dist/tests/runner.js +150 -1
- package/dist/tests/spec.js +33 -1
- package/dist/themes.js +39 -1
- package/dist/workflow/adapters/db-adapter.js +83 -1
- package/dist/workflow/adapters/file-adapter.js +11 -1
- package/dist/workflow/adapters/index.js +5 -1
- package/dist/workflow/adapters/memory-store.js +58 -1
- package/dist/workflow/expression.js +98 -1
- package/dist/workflow/index.js +9 -1
- package/dist/workflow/runner.js +337 -1
- package/dist/workflow/sla-monitor.js +47 -1
- package/dist/workflow/spec.js +32 -1
- package/dist/workflow/validation.js +175 -1
- package/package.json +11 -4
|
@@ -1 +1,317 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { ScalarTypeEnum } from "../schema/dist/ScalarTypeEnum.js";
|
|
2
|
+
import { SchemaModel } from "../schema/dist/SchemaModel.js";
|
|
3
|
+
import "../schema/dist/index.js";
|
|
4
|
+
import { defineCommand, defineQuery } from "../spec.js";
|
|
5
|
+
|
|
6
|
+
//#region src/knowledge/contracts.ts
|
|
7
|
+
const KnowledgeSyncSchedule = new SchemaModel({
|
|
8
|
+
name: "KnowledgeSyncSchedule",
|
|
9
|
+
fields: {
|
|
10
|
+
enabled: {
|
|
11
|
+
type: ScalarTypeEnum.Boolean(),
|
|
12
|
+
isOptional: false
|
|
13
|
+
},
|
|
14
|
+
cron: {
|
|
15
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
16
|
+
isOptional: true
|
|
17
|
+
},
|
|
18
|
+
intervalMs: {
|
|
19
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
20
|
+
isOptional: true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const KnowledgeSourceRecord = new SchemaModel({
|
|
25
|
+
name: "KnowledgeSourceRecord",
|
|
26
|
+
fields: {
|
|
27
|
+
id: {
|
|
28
|
+
type: ScalarTypeEnum.ID(),
|
|
29
|
+
isOptional: false
|
|
30
|
+
},
|
|
31
|
+
tenantId: {
|
|
32
|
+
type: ScalarTypeEnum.ID(),
|
|
33
|
+
isOptional: false
|
|
34
|
+
},
|
|
35
|
+
spaceKey: {
|
|
36
|
+
type: ScalarTypeEnum.NonEmptyString(),
|
|
37
|
+
isOptional: false
|
|
38
|
+
},
|
|
39
|
+
spaceVersion: {
|
|
40
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
41
|
+
isOptional: false
|
|
42
|
+
},
|
|
43
|
+
label: {
|
|
44
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
45
|
+
isOptional: false
|
|
46
|
+
},
|
|
47
|
+
sourceType: {
|
|
48
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
49
|
+
isOptional: false
|
|
50
|
+
},
|
|
51
|
+
syncSchedule: {
|
|
52
|
+
type: KnowledgeSyncSchedule,
|
|
53
|
+
isOptional: true
|
|
54
|
+
},
|
|
55
|
+
lastSyncStatus: {
|
|
56
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
57
|
+
isOptional: true
|
|
58
|
+
},
|
|
59
|
+
lastSyncAt: {
|
|
60
|
+
type: ScalarTypeEnum.DateTime(),
|
|
61
|
+
isOptional: true
|
|
62
|
+
},
|
|
63
|
+
itemsProcessed: {
|
|
64
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
65
|
+
isOptional: true
|
|
66
|
+
},
|
|
67
|
+
createdAt: {
|
|
68
|
+
type: ScalarTypeEnum.DateTime(),
|
|
69
|
+
isOptional: true
|
|
70
|
+
},
|
|
71
|
+
updatedAt: {
|
|
72
|
+
type: ScalarTypeEnum.DateTime(),
|
|
73
|
+
isOptional: true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const CreateKnowledgeSourceInput = new SchemaModel({
|
|
78
|
+
name: "CreateKnowledgeSourceInput",
|
|
79
|
+
fields: {
|
|
80
|
+
tenantId: {
|
|
81
|
+
type: ScalarTypeEnum.ID(),
|
|
82
|
+
isOptional: false
|
|
83
|
+
},
|
|
84
|
+
spaceKey: {
|
|
85
|
+
type: ScalarTypeEnum.NonEmptyString(),
|
|
86
|
+
isOptional: false
|
|
87
|
+
},
|
|
88
|
+
spaceVersion: {
|
|
89
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
90
|
+
isOptional: false
|
|
91
|
+
},
|
|
92
|
+
label: {
|
|
93
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
94
|
+
isOptional: false
|
|
95
|
+
},
|
|
96
|
+
sourceType: {
|
|
97
|
+
type: ScalarTypeEnum.NonEmptyString(),
|
|
98
|
+
isOptional: false
|
|
99
|
+
},
|
|
100
|
+
config: {
|
|
101
|
+
type: ScalarTypeEnum.JSONObject(),
|
|
102
|
+
isOptional: false
|
|
103
|
+
},
|
|
104
|
+
syncSchedule: {
|
|
105
|
+
type: KnowledgeSyncSchedule,
|
|
106
|
+
isOptional: true
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const UpdateKnowledgeSourceInput = new SchemaModel({
|
|
111
|
+
name: "UpdateKnowledgeSourceInput",
|
|
112
|
+
fields: {
|
|
113
|
+
sourceId: {
|
|
114
|
+
type: ScalarTypeEnum.ID(),
|
|
115
|
+
isOptional: false
|
|
116
|
+
},
|
|
117
|
+
label: {
|
|
118
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
119
|
+
isOptional: true
|
|
120
|
+
},
|
|
121
|
+
config: {
|
|
122
|
+
type: ScalarTypeEnum.JSONObject(),
|
|
123
|
+
isOptional: true
|
|
124
|
+
},
|
|
125
|
+
syncSchedule: {
|
|
126
|
+
type: KnowledgeSyncSchedule,
|
|
127
|
+
isOptional: true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const DeleteKnowledgeSourceInput = new SchemaModel({
|
|
132
|
+
name: "DeleteKnowledgeSourceInput",
|
|
133
|
+
fields: { sourceId: {
|
|
134
|
+
type: ScalarTypeEnum.ID(),
|
|
135
|
+
isOptional: false
|
|
136
|
+
} }
|
|
137
|
+
});
|
|
138
|
+
const DeleteKnowledgeSourceOutput = new SchemaModel({
|
|
139
|
+
name: "DeleteKnowledgeSourceOutput",
|
|
140
|
+
fields: { success: {
|
|
141
|
+
type: ScalarTypeEnum.Boolean(),
|
|
142
|
+
isOptional: false
|
|
143
|
+
} }
|
|
144
|
+
});
|
|
145
|
+
const ListKnowledgeSourcesInput = new SchemaModel({
|
|
146
|
+
name: "ListKnowledgeSourcesInput",
|
|
147
|
+
fields: {
|
|
148
|
+
tenantId: {
|
|
149
|
+
type: ScalarTypeEnum.ID(),
|
|
150
|
+
isOptional: false
|
|
151
|
+
},
|
|
152
|
+
spaceKey: {
|
|
153
|
+
type: ScalarTypeEnum.NonEmptyString(),
|
|
154
|
+
isOptional: true
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
const ListKnowledgeSourcesOutput = new SchemaModel({
|
|
159
|
+
name: "ListKnowledgeSourcesOutput",
|
|
160
|
+
fields: { sources: {
|
|
161
|
+
type: KnowledgeSourceRecord,
|
|
162
|
+
isOptional: false,
|
|
163
|
+
isArray: true
|
|
164
|
+
} }
|
|
165
|
+
});
|
|
166
|
+
const TriggerKnowledgeSyncInput = new SchemaModel({
|
|
167
|
+
name: "TriggerKnowledgeSyncInput",
|
|
168
|
+
fields: { sourceId: {
|
|
169
|
+
type: ScalarTypeEnum.ID(),
|
|
170
|
+
isOptional: false
|
|
171
|
+
} }
|
|
172
|
+
});
|
|
173
|
+
const TriggerKnowledgeSyncOutput = new SchemaModel({
|
|
174
|
+
name: "TriggerKnowledgeSyncOutput",
|
|
175
|
+
fields: {
|
|
176
|
+
success: {
|
|
177
|
+
type: ScalarTypeEnum.Boolean(),
|
|
178
|
+
isOptional: false
|
|
179
|
+
},
|
|
180
|
+
itemsProcessed: {
|
|
181
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
182
|
+
isOptional: true
|
|
183
|
+
},
|
|
184
|
+
error: {
|
|
185
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
186
|
+
isOptional: true
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const CreateKnowledgeSource = defineCommand({
|
|
191
|
+
meta: {
|
|
192
|
+
name: "knowledge.source.create",
|
|
193
|
+
version: 1,
|
|
194
|
+
description: "Create a knowledge source binding for a tenant.",
|
|
195
|
+
goal: "Onboard a new knowledge ingestion source such as Notion or uploads.",
|
|
196
|
+
context: "Used by Ops and App Studio to configure knowledge ingestion per tenant and space.",
|
|
197
|
+
owners: ["platform.knowledge"],
|
|
198
|
+
tags: ["knowledge", "sources"],
|
|
199
|
+
stability: "experimental"
|
|
200
|
+
},
|
|
201
|
+
io: {
|
|
202
|
+
input: CreateKnowledgeSourceInput,
|
|
203
|
+
output: KnowledgeSourceRecord
|
|
204
|
+
},
|
|
205
|
+
policy: {
|
|
206
|
+
auth: "admin",
|
|
207
|
+
policies: [{
|
|
208
|
+
name: "platform.knowledge.manage",
|
|
209
|
+
version: 1
|
|
210
|
+
}]
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const UpdateKnowledgeSource = defineCommand({
|
|
214
|
+
meta: {
|
|
215
|
+
name: "knowledge.source.update",
|
|
216
|
+
version: 1,
|
|
217
|
+
description: "Update metadata or configuration for a knowledge source.",
|
|
218
|
+
goal: "Allow rotation of credentials, sync schedules, and labels.",
|
|
219
|
+
context: "Supports editing how a tenant ingests knowledge (e.g., toggling sync cadence).",
|
|
220
|
+
owners: ["platform.knowledge"],
|
|
221
|
+
tags: ["knowledge", "sources"],
|
|
222
|
+
stability: "experimental"
|
|
223
|
+
},
|
|
224
|
+
io: {
|
|
225
|
+
input: UpdateKnowledgeSourceInput,
|
|
226
|
+
output: KnowledgeSourceRecord
|
|
227
|
+
},
|
|
228
|
+
policy: {
|
|
229
|
+
auth: "admin",
|
|
230
|
+
policies: [{
|
|
231
|
+
name: "platform.knowledge.manage",
|
|
232
|
+
version: 1
|
|
233
|
+
}]
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
const DeleteKnowledgeSource = defineCommand({
|
|
237
|
+
meta: {
|
|
238
|
+
name: "knowledge.source.delete",
|
|
239
|
+
version: 1,
|
|
240
|
+
description: "Delete a knowledge source binding for a tenant.",
|
|
241
|
+
goal: "Remove obsolete or compromised knowledge ingestion paths.",
|
|
242
|
+
context: "Ensures ephemeral or external sources can be removed cleanly without leaving residual bindings.",
|
|
243
|
+
owners: ["platform.knowledge"],
|
|
244
|
+
tags: ["knowledge", "sources"],
|
|
245
|
+
stability: "experimental"
|
|
246
|
+
},
|
|
247
|
+
io: {
|
|
248
|
+
input: DeleteKnowledgeSourceInput,
|
|
249
|
+
output: DeleteKnowledgeSourceOutput
|
|
250
|
+
},
|
|
251
|
+
policy: {
|
|
252
|
+
auth: "admin",
|
|
253
|
+
policies: [{
|
|
254
|
+
name: "platform.knowledge.manage",
|
|
255
|
+
version: 1
|
|
256
|
+
}]
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
const ListKnowledgeSources = defineQuery({
|
|
260
|
+
meta: {
|
|
261
|
+
name: "knowledge.source.list",
|
|
262
|
+
version: 1,
|
|
263
|
+
description: "List knowledge sources configured for a tenant.",
|
|
264
|
+
goal: "Provide visibility into knowledge ingest configuration and schedules.",
|
|
265
|
+
context: "Used by App Studio and Ops flows to surface knowledge sources and their health.",
|
|
266
|
+
owners: ["platform.knowledge"],
|
|
267
|
+
tags: ["knowledge", "sources"],
|
|
268
|
+
stability: "experimental"
|
|
269
|
+
},
|
|
270
|
+
io: {
|
|
271
|
+
input: ListKnowledgeSourcesInput,
|
|
272
|
+
output: ListKnowledgeSourcesOutput
|
|
273
|
+
},
|
|
274
|
+
policy: {
|
|
275
|
+
auth: "admin",
|
|
276
|
+
policies: [{
|
|
277
|
+
name: "platform.knowledge.read",
|
|
278
|
+
version: 1
|
|
279
|
+
}]
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
const TriggerKnowledgeSourceSync = defineCommand({
|
|
283
|
+
meta: {
|
|
284
|
+
name: "knowledge.source.triggerSync",
|
|
285
|
+
version: 1,
|
|
286
|
+
description: "Trigger an immediate sync for a knowledge source.",
|
|
287
|
+
goal: "Support manual or automated sync retries for knowledge ingestion.",
|
|
288
|
+
context: "Invoked by Ops tooling or monitors when knowledge content must be refreshed or reprocessed.",
|
|
289
|
+
owners: ["platform.knowledge"],
|
|
290
|
+
tags: ["knowledge", "sources"],
|
|
291
|
+
stability: "experimental"
|
|
292
|
+
},
|
|
293
|
+
io: {
|
|
294
|
+
input: TriggerKnowledgeSyncInput,
|
|
295
|
+
output: TriggerKnowledgeSyncOutput
|
|
296
|
+
},
|
|
297
|
+
policy: {
|
|
298
|
+
auth: "admin",
|
|
299
|
+
policies: [{
|
|
300
|
+
name: "platform.knowledge.manage",
|
|
301
|
+
version: 1
|
|
302
|
+
}]
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
const knowledgeContracts = {
|
|
306
|
+
CreateKnowledgeSource,
|
|
307
|
+
UpdateKnowledgeSource,
|
|
308
|
+
DeleteKnowledgeSource,
|
|
309
|
+
ListKnowledgeSources,
|
|
310
|
+
TriggerKnowledgeSourceSync
|
|
311
|
+
};
|
|
312
|
+
function registerKnowledgeContracts(registry) {
|
|
313
|
+
return registry.register(CreateKnowledgeSource).register(UpdateKnowledgeSource).register(DeleteKnowledgeSource).register(ListKnowledgeSources).register(TriggerKnowledgeSourceSync);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
//#endregion
|
|
317
|
+
export { CreateKnowledgeSource, DeleteKnowledgeSource, ListKnowledgeSources, TriggerKnowledgeSourceSync, UpdateKnowledgeSource, knowledgeContracts, registerKnowledgeContracts };
|
|
@@ -1,138 +1,22 @@
|
|
|
1
|
-
import{registerDocBlocks
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- Indexing configuration (embedding model, chunk size, vector DB slot).
|
|
24
|
-
|
|
25
|
-
## Sources & Bindings
|
|
26
|
-
|
|
27
|
-
- \`KnowledgeSourceConfig\` records tenant-specific connections (bucket,
|
|
28
|
-
Gmail labels, sync cadence). Pocket Family Office provides sample
|
|
29
|
-
configs in \`knowledge/sources.sample.ts\`.
|
|
30
|
-
- \`AppKnowledgeBinding\` associates spaces with workflows/agents and adds
|
|
31
|
-
per-tenant constraints (rate limits, scopes).
|
|
32
|
-
|
|
33
|
-
Validation ensures that:
|
|
34
|
-
|
|
35
|
-
- All referenced spaces exist in the registry.
|
|
36
|
-
- At least one source is configured per binding.
|
|
37
|
-
- External/ephemeral spaces trigger warnings for policy-sensitive flows.
|
|
38
|
-
|
|
39
|
-
## Ingestion Pipeline
|
|
40
|
-
|
|
41
|
-
Implemented in \`packages/libs/contracts/src/knowledge/ingestion\`:
|
|
42
|
-
|
|
43
|
-
1. **DocumentProcessor** – pluggable MIME extractors producing
|
|
44
|
-
\`DocumentFragment\`s.
|
|
45
|
-
2. **EmbeddingService** – batches fragments through an \`EmbeddingProvider\`
|
|
46
|
-
(Mistral in the reference implementation).
|
|
47
|
-
3. **VectorIndexer** – upserts fragments into a \`VectorStoreProvider\`
|
|
48
|
-
(Qdrant in production, with in-memory implementations for tests).
|
|
49
|
-
4. **Adapters**
|
|
50
|
-
- \`GmailIngestionAdapter\`: list threads → convert to raw documents →
|
|
51
|
-
index.
|
|
52
|
-
- \`StorageIngestionAdapter\`: fetch object from storage provider →
|
|
53
|
-
index.
|
|
54
|
-
|
|
55
|
-
Background jobs (see \`jobs/\`) orchestrate ingestion via Cloud Tasks /
|
|
56
|
-
Pub/Sub or in-memory workers. Handlers:
|
|
57
|
-
|
|
58
|
-
- \`storage-document-handler\` – resolves storage object + indexes.
|
|
59
|
-
- \`gmail-sync-handler\` – syncs threads based on label/date filters.
|
|
60
|
-
|
|
61
|
-
## Query Service
|
|
62
|
-
|
|
63
|
-
\`KnowledgeQueryService\` performs retrieval-augmented generation:
|
|
64
|
-
|
|
65
|
-
1. Embed the user query using the configured provider.
|
|
66
|
-
2. Search the vector store for top-k matches.
|
|
67
|
-
3. Compose prompts combining system instructions + contextual snippets.
|
|
68
|
-
4. Invoke the LLM provider (Mistral) and return the answer plus
|
|
69
|
-
references and token usage.
|
|
70
|
-
|
|
71
|
-
The service is designed for tooling: workflows can execute it directly
|
|
72
|
-
or through custom operations (see \`pfo.summary.generate\` contract).
|
|
73
|
-
|
|
74
|
-
## Guardrails
|
|
75
|
-
|
|
76
|
-
- Automation can only write to spaces where \`automationWritable\` is true.
|
|
77
|
-
- Canonical spaces default to high trust; external/ephemeral spaces are
|
|
78
|
-
flagged during validation.
|
|
79
|
-
- Telemetry captures query volumes per tenant + space.
|
|
80
|
-
|
|
81
|
-
## Extending
|
|
82
|
-
|
|
83
|
-
1. Define a new \`KnowledgeSpaceSpec\` with indexing/retention policies.
|
|
84
|
-
2. Add sources pointing to storage providers or APIs.
|
|
85
|
-
3. Register adapters if ingestion requires bespoke logic.
|
|
86
|
-
4. Reference the space in blueprints (\`AppKnowledgeBinding\`) and update
|
|
87
|
-
workflows/agents accordingly.
|
|
88
|
-
|
|
89
|
-
The Pocket Family Office tests (\`tests/pocket-family-office.test.ts\`)
|
|
90
|
-
show how to wire the ingestion pipeline, index a document, and run an
|
|
91
|
-
end-to-end knowledge query using in-memory providers.
|
|
92
|
-
## Knowledge Spaces & Guardrails
|
|
93
|
-
|
|
94
|
-
Knowledge surfaces (\`KnowledgeSpaceSpec\`) describe curated corpora that agents and workflows can consult. Tenant bindings (\`AppKnowledgeBinding\`) declare which spaces are active, who can use them, and optional usage constraints.
|
|
95
|
-
|
|
96
|
-
### Binding recap
|
|
97
|
-
|
|
98
|
-
- \`spaceKey\` / \`spaceVersion\`: pointer to the \`KnowledgeSpaceSpec\`
|
|
99
|
-
- \`scope.workflows\` / \`scope.agents\`: explicit allow-lists for consumers
|
|
100
|
-
- \`constraints.maxTokensPerQuery\` & \`constraints.maxQueriesPerMinute\`: throttling knobs for LLM-backed search
|
|
101
|
-
- \`required\`: mark the binding as blocking (defaults to \`true\`)
|
|
102
|
-
|
|
103
|
-
At runtime, \`ResolvedAppConfig.knowledge\` contains \`ResolvedKnowledge\` entries with the bound space, active sources, and the binding metadata above.
|
|
104
|
-
|
|
105
|
-
### KnowledgeAccessGuard
|
|
106
|
-
|
|
107
|
-
\`KnowledgeAccessGuard\` (\`@lssm/lib.contracts/knowledge/runtime\`) centralises the access checks that must run before any workflow/agent reads or mutates a knowledge space.
|
|
108
|
-
|
|
109
|
-
\`\`\`ts
|
|
110
|
-
import { KnowledgeAccessGuard } from '@lssm/lib.contracts/knowledge/runtime';
|
|
111
|
-
|
|
112
|
-
const guard = new KnowledgeAccessGuard({
|
|
113
|
-
disallowWriteCategories: ['external', 'ephemeral'], // default
|
|
114
|
-
requireWorkflowBinding: true,
|
|
115
|
-
requireAgentBinding: false,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const result = guard.checkAccess(resolvedKnowledge, {
|
|
119
|
-
tenantId,
|
|
120
|
-
appId,
|
|
121
|
-
workflowName: 'order-processing',
|
|
122
|
-
operation: 'read', // or 'write' / 'search'
|
|
123
|
-
}, resolvedAppConfig);
|
|
124
|
-
|
|
125
|
-
if (!result.allowed) {
|
|
126
|
-
throw new Error(result.reason);
|
|
127
|
-
}
|
|
128
|
-
\`\`\`
|
|
129
|
-
|
|
130
|
-
Key behaviours:
|
|
131
|
-
|
|
132
|
-
- **Binding**: rejects access when the space is not present in the resolved tenant config.
|
|
133
|
-
- **Category guardrails**: blocks writes to \`external\` and \`ephemeral\` spaces by default; allows reads but emits warnings for \`ephemeral\`.
|
|
134
|
-
- **Workflow/agent scoping**: when \`requireWorkflowBinding\` or \`requireAgentBinding\` is enabled, only explicitly authorised consumers may access the space.
|
|
135
|
-
|
|
136
|
-
Use the guard inside workflow operations or agent resolvers to guarantee multi-tenant isolation and honour data governance rules.
|
|
137
|
-
|
|
138
|
-
`}];e(t);export{t as tech_contracts_knowledge_DocBlocks};
|
|
1
|
+
import { registerDocBlocks } from "../../docs/registry.js";
|
|
2
|
+
import "../../registry.js";
|
|
3
|
+
|
|
4
|
+
//#region src/knowledge/docs/knowledge.docblock.ts
|
|
5
|
+
const tech_contracts_knowledge_DocBlocks = [{
|
|
6
|
+
id: "docs.tech.contracts.knowledge",
|
|
7
|
+
title: "Knowledge Layer",
|
|
8
|
+
summary: "The knowledge layer turns unstructured inputs (uploads, email threads,",
|
|
9
|
+
kind: "reference",
|
|
10
|
+
visibility: "public",
|
|
11
|
+
route: "/docs/tech/contracts/knowledge",
|
|
12
|
+
tags: [
|
|
13
|
+
"tech",
|
|
14
|
+
"contracts",
|
|
15
|
+
"knowledge"
|
|
16
|
+
],
|
|
17
|
+
body: "# Knowledge Layer\n\nThe knowledge layer turns unstructured inputs (uploads, email threads,\nnotes) into searchable context for agents and workflows. The Pocket\nFamily Office vertical ships a minimal but production-ready stack that\ncovers ingestion, indexing, querying, and guardrails.\n\n## Knowledge Spaces\n\nKnowledge is organised via `KnowledgeSpaceSpec` definitions under\n`packages/libs/contracts/src/knowledge/spaces`:\n\n- `knowledge.financial-docs` – canonical invoices, bills, and contracts.\n- `knowledge.email-threads` – operational Gmail threads.\n- `knowledge.support-faq` / `knowledge.product-canon` – reusable shared\n spaces available to any vertical.\n\nEach space defines:\n\n- Ownership metadata (domain, owners, stability tags).\n- Retention policy (TTL/archival).\n- Access policy (trust level, automation write permissions).\n- Indexing configuration (embedding model, chunk size, vector DB slot).\n\n## Sources & Bindings\n\n- `KnowledgeSourceConfig` records tenant-specific connections (bucket,\n Gmail labels, sync cadence). Pocket Family Office provides sample\n configs in `knowledge/sources.sample.ts`.\n- `AppKnowledgeBinding` associates spaces with workflows/agents and adds\n per-tenant constraints (rate limits, scopes).\n\nValidation ensures that:\n\n- All referenced spaces exist in the registry.\n- At least one source is configured per binding.\n- External/ephemeral spaces trigger warnings for policy-sensitive flows.\n\n## Ingestion Pipeline\n\nImplemented in `packages/libs/contracts/src/knowledge/ingestion`:\n\n1. **DocumentProcessor** – pluggable MIME extractors producing\n `DocumentFragment`s.\n2. **EmbeddingService** – batches fragments through an `EmbeddingProvider`\n (Mistral in the reference implementation).\n3. **VectorIndexer** – upserts fragments into a `VectorStoreProvider`\n (Qdrant in production, with in-memory implementations for tests).\n4. **Adapters**\n - `GmailIngestionAdapter`: list threads → convert to raw documents →\n index.\n - `StorageIngestionAdapter`: fetch object from storage provider →\n index.\n\nBackground jobs (see `jobs/`) orchestrate ingestion via Cloud Tasks /\nPub/Sub or in-memory workers. Handlers:\n\n- `storage-document-handler` – resolves storage object + indexes.\n- `gmail-sync-handler` – syncs threads based on label/date filters.\n\n## Query Service\n\n`KnowledgeQueryService` performs retrieval-augmented generation:\n\n1. Embed the user query using the configured provider.\n2. Search the vector store for top-k matches.\n3. Compose prompts combining system instructions + contextual snippets.\n4. Invoke the LLM provider (Mistral) and return the answer plus\n references and token usage.\n\nThe service is designed for tooling: workflows can execute it directly\nor through custom operations (see `pfo.summary.generate` contract).\n\n## Guardrails\n\n- Automation can only write to spaces where `automationWritable` is true.\n- Canonical spaces default to high trust; external/ephemeral spaces are\n flagged during validation.\n- Telemetry captures query volumes per tenant + space.\n\n## Extending\n\n1. Define a new `KnowledgeSpaceSpec` with indexing/retention policies.\n2. Add sources pointing to storage providers or APIs.\n3. Register adapters if ingestion requires bespoke logic.\n4. Reference the space in blueprints (`AppKnowledgeBinding`) and update\n workflows/agents accordingly.\n\nThe Pocket Family Office tests (`tests/pocket-family-office.test.ts`)\nshow how to wire the ingestion pipeline, index a document, and run an\nend-to-end knowledge query using in-memory providers.\n## Knowledge Spaces & Guardrails\n\nKnowledge surfaces (`KnowledgeSpaceSpec`) describe curated corpora that agents and workflows can consult. Tenant bindings (`AppKnowledgeBinding`) declare which spaces are active, who can use them, and optional usage constraints.\n\n### Binding recap\n\n- `spaceKey` / `spaceVersion`: pointer to the `KnowledgeSpaceSpec`\n- `scope.workflows` / `scope.agents`: explicit allow-lists for consumers\n- `constraints.maxTokensPerQuery` & `constraints.maxQueriesPerMinute`: throttling knobs for LLM-backed search\n- `required`: mark the binding as blocking (defaults to `true`)\n\nAt runtime, `ResolvedAppConfig.knowledge` contains `ResolvedKnowledge` entries with the bound space, active sources, and the binding metadata above.\n\n### KnowledgeAccessGuard\n\n`KnowledgeAccessGuard` (`@lssm/lib.contracts/knowledge/runtime`) centralises the access checks that must run before any workflow/agent reads or mutates a knowledge space.\n\n```ts\nimport { KnowledgeAccessGuard } from '@lssm/lib.contracts/knowledge/runtime';\n\nconst guard = new KnowledgeAccessGuard({\n disallowWriteCategories: ['external', 'ephemeral'], // default\n requireWorkflowBinding: true,\n requireAgentBinding: false,\n});\n\nconst result = guard.checkAccess(resolvedKnowledge, {\n tenantId,\n appId,\n workflowName: 'order-processing',\n operation: 'read', // or 'write' / 'search'\n}, resolvedAppConfig);\n\nif (!result.allowed) {\n throw new Error(result.reason);\n}\n```\n\nKey behaviours:\n\n- **Binding**: rejects access when the space is not present in the resolved tenant config.\n- **Category guardrails**: blocks writes to `external` and `ephemeral` spaces by default; allows reads but emits warnings for `ephemeral`.\n- **Workflow/agent scoping**: when `requireWorkflowBinding` or `requireAgentBinding` is enabled, only explicitly authorised consumers may access the space.\n\nUse the guard inside workflow operations or agent resolvers to guarantee multi-tenant isolation and honour data governance rules.\n\n"
|
|
18
|
+
}];
|
|
19
|
+
registerDocBlocks(tech_contracts_knowledge_DocBlocks);
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { tech_contracts_knowledge_DocBlocks };
|
package/dist/knowledge/index.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { KnowledgeSpaceRegistry, makeKnowledgeSpaceKey } from "./spec.js";
|
|
2
|
+
import { productCanonKnowledgeSpace, registerProductCanonKnowledgeSpace } from "./spaces/product-canon.js";
|
|
3
|
+
import { registerSupportFaqKnowledgeSpace, supportFaqKnowledgeSpace } from "./spaces/support-faq.js";
|
|
4
|
+
import { emailThreadsKnowledgeSpace, registerEmailThreadsKnowledgeSpace } from "./spaces/email-threads.js";
|
|
5
|
+
import { registerUploadedDocsKnowledgeSpace, uploadedDocsKnowledgeSpace } from "./spaces/uploaded-docs.js";
|
|
6
|
+
import { financialDocsKnowledgeSpace, registerFinancialDocsKnowledgeSpace } from "./spaces/financial-docs.js";
|
|
7
|
+
import { financialOverviewKnowledgeSpace, registerFinancialOverviewKnowledgeSpace } from "./spaces/financial-overview.js";
|
|
8
|
+
import "./spaces/index.js";
|
|
9
|
+
|
|
10
|
+
export { KnowledgeSpaceRegistry, emailThreadsKnowledgeSpace, financialDocsKnowledgeSpace, financialOverviewKnowledgeSpace, makeKnowledgeSpaceKey, productCanonKnowledgeSpace, registerEmailThreadsKnowledgeSpace, registerFinancialDocsKnowledgeSpace, registerFinancialOverviewKnowledgeSpace, registerProductCanonKnowledgeSpace, registerSupportFaqKnowledgeSpace, registerUploadedDocsKnowledgeSpace, supportFaqKnowledgeSpace, uploadedDocsKnowledgeSpace };
|
|
@@ -1 +1,54 @@
|
|
|
1
|
-
import{Buffer
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/knowledge/ingestion/document-processor.ts
|
|
4
|
+
var DocumentProcessor = class {
|
|
5
|
+
extractors = /* @__PURE__ */ new Map();
|
|
6
|
+
constructor() {
|
|
7
|
+
this.registerExtractor("text/plain", this.extractText);
|
|
8
|
+
this.registerExtractor("application/json", this.extractJson);
|
|
9
|
+
}
|
|
10
|
+
registerExtractor(mimeType, extractor) {
|
|
11
|
+
this.extractors.set(mimeType.toLowerCase(), extractor);
|
|
12
|
+
}
|
|
13
|
+
async process(document) {
|
|
14
|
+
const extractor = this.extractors.get(document.mimeType.toLowerCase()) ?? this.extractors.get("*/*");
|
|
15
|
+
if (!extractor) throw new Error(`No extractor registered for mime type ${document.mimeType}`);
|
|
16
|
+
const fragments = await extractor(document);
|
|
17
|
+
if (fragments.length === 0) return [{
|
|
18
|
+
id: `${document.id}:0`,
|
|
19
|
+
documentId: document.id,
|
|
20
|
+
text: "",
|
|
21
|
+
metadata: document.metadata
|
|
22
|
+
}];
|
|
23
|
+
return fragments;
|
|
24
|
+
}
|
|
25
|
+
async extractText(document) {
|
|
26
|
+
const text = Buffer.from(document.data).toString("utf-8");
|
|
27
|
+
return [{
|
|
28
|
+
id: `${document.id}:0`,
|
|
29
|
+
documentId: document.id,
|
|
30
|
+
text,
|
|
31
|
+
metadata: document.metadata
|
|
32
|
+
}];
|
|
33
|
+
}
|
|
34
|
+
async extractJson(document) {
|
|
35
|
+
const text = Buffer.from(document.data).toString("utf-8");
|
|
36
|
+
try {
|
|
37
|
+
const json = JSON.parse(text);
|
|
38
|
+
return [{
|
|
39
|
+
id: `${document.id}:0`,
|
|
40
|
+
documentId: document.id,
|
|
41
|
+
text: JSON.stringify(json, null, 2),
|
|
42
|
+
metadata: {
|
|
43
|
+
...document.metadata,
|
|
44
|
+
contentType: "application/json"
|
|
45
|
+
}
|
|
46
|
+
}];
|
|
47
|
+
} catch {
|
|
48
|
+
return this.extractText(document);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { DocumentProcessor };
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/knowledge/ingestion/embedding-service.ts
|
|
2
|
+
var EmbeddingService = class {
|
|
3
|
+
provider;
|
|
4
|
+
batchSize;
|
|
5
|
+
constructor(provider, batchSize = 16) {
|
|
6
|
+
this.provider = provider;
|
|
7
|
+
this.batchSize = batchSize;
|
|
8
|
+
}
|
|
9
|
+
async embedFragments(fragments) {
|
|
10
|
+
const results = [];
|
|
11
|
+
for (let i = 0; i < fragments.length; i += this.batchSize) {
|
|
12
|
+
const documents = fragments.slice(i, i + this.batchSize).map((fragment) => ({
|
|
13
|
+
id: fragment.id,
|
|
14
|
+
text: fragment.text,
|
|
15
|
+
metadata: fragment.metadata
|
|
16
|
+
}));
|
|
17
|
+
const embeddings = await this.provider.embedDocuments(documents);
|
|
18
|
+
results.push(...embeddings);
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { EmbeddingService };
|
|
@@ -1,6 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/knowledge/ingestion/gmail-adapter.ts
|
|
2
|
+
var GmailIngestionAdapter = class {
|
|
3
|
+
constructor(gmail, processor, embeddings, indexer) {
|
|
4
|
+
this.gmail = gmail;
|
|
5
|
+
this.processor = processor;
|
|
6
|
+
this.embeddings = embeddings;
|
|
7
|
+
this.indexer = indexer;
|
|
8
|
+
}
|
|
9
|
+
async syncThreads(query) {
|
|
10
|
+
const threads = await this.gmail.listThreads(query);
|
|
11
|
+
for (const thread of threads) await this.ingestThread(thread);
|
|
12
|
+
}
|
|
13
|
+
async ingestThread(thread) {
|
|
14
|
+
const document = this.toRawDocument(thread);
|
|
15
|
+
const fragments = await this.processor.process(document);
|
|
16
|
+
const embeddings = await this.embeddings.embedFragments(fragments);
|
|
17
|
+
await this.indexer.upsert(fragments, embeddings);
|
|
18
|
+
}
|
|
19
|
+
toRawDocument(thread) {
|
|
20
|
+
const content = composeThreadText(thread);
|
|
21
|
+
return {
|
|
22
|
+
id: thread.id,
|
|
23
|
+
mimeType: "text/plain",
|
|
24
|
+
data: Buffer.from(content, "utf-8"),
|
|
25
|
+
metadata: {
|
|
26
|
+
subject: thread.subject ?? "",
|
|
27
|
+
participants: thread.participants.map((p) => p.email).join(", "),
|
|
28
|
+
updatedAt: thread.updatedAt.toISOString()
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function composeThreadText(thread) {
|
|
34
|
+
const header = [`Subject: ${thread.subject ?? ""}`, `Snippet: ${thread.snippet ?? ""}`];
|
|
35
|
+
const messageTexts = thread.messages.map((message) => {
|
|
36
|
+
const parts = [`From: ${formatAddress(message.from)}`, `To: ${message.to.map(formatAddress).join(", ")}`];
|
|
37
|
+
if (message.sentAt) parts.push(`Date: ${message.sentAt.toISOString()}`);
|
|
38
|
+
const body = message.textBody ?? stripHtml(message.htmlBody ?? "");
|
|
39
|
+
return `${parts.join("\n")}\n\n${body ?? ""}`;
|
|
40
|
+
});
|
|
41
|
+
return [...header, ...messageTexts].join("\n\n---\n\n");
|
|
42
|
+
}
|
|
43
|
+
function formatAddress(address) {
|
|
44
|
+
return address.name ? `${address.name} <${address.email}>` : address.email;
|
|
45
|
+
}
|
|
46
|
+
function stripHtml(html) {
|
|
47
|
+
return html.replace(/<[^>]+>/g, " ");
|
|
48
|
+
}
|
|
3
49
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
`)}function n(e){return e.name?`${e.name} <${e.email}>`:e.email}function r(e){return e.replace(/<[^>]+>/g,` `)}export{e as GmailIngestionAdapter};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { GmailIngestionAdapter };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DocumentProcessor } from "./document-processor.js";
|
|
2
|
+
import { EmbeddingService } from "./embedding-service.js";
|
|
3
|
+
import { GmailIngestionAdapter } from "./gmail-adapter.js";
|
|
4
|
+
import { VectorIndexer } from "./vector-indexer.js";
|
|
5
|
+
import { StorageIngestionAdapter } from "./storage-adapter.js";
|
|
6
|
+
|
|
7
|
+
export { DocumentProcessor, EmbeddingService, GmailIngestionAdapter, StorageIngestionAdapter, VectorIndexer };
|