soma-protocol 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.
- package/LICENSE +190 -0
- package/README.md +326 -0
- package/dist/adapters/bun.d.ts +10 -0
- package/dist/adapters/bun.d.ts.map +1 -0
- package/dist/adapters/bun.js +15 -0
- package/dist/adapters/bun.js.map +1 -0
- package/dist/adapters/drizzle.d.ts +17 -0
- package/dist/adapters/drizzle.d.ts.map +1 -0
- package/dist/adapters/drizzle.js +21 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/index.d.ts +6 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +6 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/pg.d.ts +16 -0
- package/dist/adapters/pg.d.ts.map +1 -0
- package/dist/adapters/pg.js +18 -0
- package/dist/adapters/pg.js.map +1 -0
- package/dist/adapters/postgres.d.ts +14 -0
- package/dist/adapters/postgres.d.ts.map +1 -0
- package/dist/adapters/postgres.js +17 -0
- package/dist/adapters/postgres.js.map +1 -0
- package/dist/adapters/typeorm.d.ts +15 -0
- package/dist/adapters/typeorm.d.ts.map +1 -0
- package/dist/adapters/typeorm.js +18 -0
- package/dist/adapters/typeorm.js.map +1 -0
- package/dist/agent/index.d.ts +7 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/interfaces/agent-meta.interface.d.ts +13 -0
- package/dist/agent/interfaces/agent-meta.interface.d.ts.map +1 -0
- package/dist/agent/interfaces/agent-meta.interface.js +2 -0
- package/dist/agent/interfaces/agent-meta.interface.js.map +1 -0
- package/dist/agent/interfaces/agent-state.interface.d.ts +14 -0
- package/dist/agent/interfaces/agent-state.interface.d.ts.map +1 -0
- package/dist/agent/interfaces/agent-state.interface.js +2 -0
- package/dist/agent/interfaces/agent-state.interface.js.map +1 -0
- package/dist/agent/interfaces/memory.interface.d.ts +174 -0
- package/dist/agent/interfaces/memory.interface.d.ts.map +1 -0
- package/dist/agent/interfaces/memory.interface.js +3 -0
- package/dist/agent/interfaces/memory.interface.js.map +1 -0
- package/dist/agent/interfaces/persona.interface.d.ts +10 -0
- package/dist/agent/interfaces/persona.interface.d.ts.map +1 -0
- package/dist/agent/interfaces/persona.interface.js +2 -0
- package/dist/agent/interfaces/persona.interface.js.map +1 -0
- package/dist/agent/interfaces/soma-agents.interface.d.ts +9 -0
- package/dist/agent/interfaces/soma-agents.interface.d.ts.map +1 -0
- package/dist/agent/interfaces/soma-agents.interface.js +2 -0
- package/dist/agent/interfaces/soma-agents.interface.js.map +1 -0
- package/dist/agent/types/mood-and-communication.type.d.ts +3 -0
- package/dist/agent/types/mood-and-communication.type.d.ts.map +1 -0
- package/dist/agent/types/mood-and-communication.type.js +2 -0
- package/dist/agent/types/mood-and-communication.type.js.map +1 -0
- package/dist/extensions/emotional/emotional.router.d.ts +9 -0
- package/dist/extensions/emotional/emotional.router.d.ts.map +1 -0
- package/dist/extensions/emotional/emotional.router.js +91 -0
- package/dist/extensions/emotional/emotional.router.js.map +1 -0
- package/dist/extensions/emotional/emotional.service.d.ts +16 -0
- package/dist/extensions/emotional/emotional.service.d.ts.map +1 -0
- package/dist/extensions/emotional/emotional.service.js +161 -0
- package/dist/extensions/emotional/emotional.service.js.map +1 -0
- package/dist/extensions/emotional/errors.d.ts +9 -0
- package/dist/extensions/emotional/errors.d.ts.map +1 -0
- package/dist/extensions/emotional/errors.js +17 -0
- package/dist/extensions/emotional/errors.js.map +1 -0
- package/dist/extensions/emotional/index.d.ts +7 -0
- package/dist/extensions/emotional/index.d.ts.map +1 -0
- package/dist/extensions/emotional/index.js +6 -0
- package/dist/extensions/emotional/index.js.map +1 -0
- package/dist/extensions/emotional/schema.d.ts +372 -0
- package/dist/extensions/emotional/schema.d.ts.map +1 -0
- package/dist/extensions/emotional/schema.js +84 -0
- package/dist/extensions/emotional/schema.js.map +1 -0
- package/dist/extensions/emotional/store.d.ts +15 -0
- package/dist/extensions/emotional/store.d.ts.map +1 -0
- package/dist/extensions/emotional/store.js +123 -0
- package/dist/extensions/emotional/store.js.map +1 -0
- package/dist/extensions/emotional/types.d.ts +87 -0
- package/dist/extensions/emotional/types.d.ts.map +1 -0
- package/dist/extensions/emotional/types.js +2 -0
- package/dist/extensions/emotional/types.js.map +1 -0
- package/dist/extensions/events/bus.d.ts +17 -0
- package/dist/extensions/events/bus.d.ts.map +1 -0
- package/dist/extensions/events/bus.js +38 -0
- package/dist/extensions/events/bus.js.map +1 -0
- package/dist/extensions/events/clickhouse-client.d.ts +12 -0
- package/dist/extensions/events/clickhouse-client.d.ts.map +1 -0
- package/dist/extensions/events/clickhouse-client.js +63 -0
- package/dist/extensions/events/clickhouse-client.js.map +1 -0
- package/dist/extensions/events/index.d.ts +3 -0
- package/dist/extensions/events/index.d.ts.map +1 -0
- package/dist/extensions/events/index.js +3 -0
- package/dist/extensions/events/index.js.map +1 -0
- package/dist/extensions/identity/generate-instructions.d.ts +8 -0
- package/dist/extensions/identity/generate-instructions.d.ts.map +1 -0
- package/dist/extensions/identity/generate-instructions.js +58 -0
- package/dist/extensions/identity/generate-instructions.js.map +1 -0
- package/dist/extensions/identity/identity.router.d.ts +8 -0
- package/dist/extensions/identity/identity.router.d.ts.map +1 -0
- package/dist/extensions/identity/identity.router.js +136 -0
- package/dist/extensions/identity/identity.router.js.map +1 -0
- package/dist/extensions/identity/identity.schema.d.ts +145 -0
- package/dist/extensions/identity/identity.schema.d.ts.map +1 -0
- package/dist/extensions/identity/identity.schema.js +71 -0
- package/dist/extensions/identity/identity.schema.js.map +1 -0
- package/dist/extensions/identity/identity.service.d.ts +19 -0
- package/dist/extensions/identity/identity.service.d.ts.map +1 -0
- package/dist/extensions/identity/identity.service.js +194 -0
- package/dist/extensions/identity/identity.service.js.map +1 -0
- package/dist/extensions/identity/identity.store.d.ts +18 -0
- package/dist/extensions/identity/identity.store.d.ts.map +1 -0
- package/dist/extensions/identity/identity.store.js +126 -0
- package/dist/extensions/identity/identity.store.js.map +1 -0
- package/dist/extensions/identity/identity.types.d.ts +54 -0
- package/dist/extensions/identity/identity.types.d.ts.map +1 -0
- package/dist/extensions/identity/identity.types.js +2 -0
- package/dist/extensions/identity/identity.types.js.map +1 -0
- package/dist/extensions/identity/index.d.ts +7 -0
- package/dist/extensions/identity/index.d.ts.map +1 -0
- package/dist/extensions/identity/index.js +7 -0
- package/dist/extensions/identity/index.js.map +1 -0
- package/dist/extensions/learning/distiller.d.ts +14 -0
- package/dist/extensions/learning/distiller.d.ts.map +1 -0
- package/dist/extensions/learning/distiller.js +126 -0
- package/dist/extensions/learning/distiller.js.map +1 -0
- package/dist/extensions/learning/errors.d.ts +26 -0
- package/dist/extensions/learning/errors.d.ts.map +1 -0
- package/dist/extensions/learning/errors.js +51 -0
- package/dist/extensions/learning/errors.js.map +1 -0
- package/dist/extensions/learning/index.d.ts +9 -0
- package/dist/extensions/learning/index.d.ts.map +1 -0
- package/dist/extensions/learning/index.js +8 -0
- package/dist/extensions/learning/index.js.map +1 -0
- package/dist/extensions/learning/observation.d.ts +13 -0
- package/dist/extensions/learning/observation.d.ts.map +1 -0
- package/dist/extensions/learning/observation.js +128 -0
- package/dist/extensions/learning/observation.js.map +1 -0
- package/dist/extensions/learning/router.d.ts +15 -0
- package/dist/extensions/learning/router.d.ts.map +1 -0
- package/dist/extensions/learning/router.js +245 -0
- package/dist/extensions/learning/router.js.map +1 -0
- package/dist/extensions/learning/schema.d.ts +472 -0
- package/dist/extensions/learning/schema.d.ts.map +1 -0
- package/dist/extensions/learning/schema.js +229 -0
- package/dist/extensions/learning/schema.js.map +1 -0
- package/dist/extensions/learning/scorecard.d.ts +7 -0
- package/dist/extensions/learning/scorecard.d.ts.map +1 -0
- package/dist/extensions/learning/scorecard.js +50 -0
- package/dist/extensions/learning/scorecard.js.map +1 -0
- package/dist/extensions/learning/store.d.ts +25 -0
- package/dist/extensions/learning/store.d.ts.map +1 -0
- package/dist/extensions/learning/store.js +305 -0
- package/dist/extensions/learning/store.js.map +1 -0
- package/dist/extensions/learning/types.d.ts +212 -0
- package/dist/extensions/learning/types.d.ts.map +1 -0
- package/dist/extensions/learning/types.js +3 -0
- package/dist/extensions/learning/types.js.map +1 -0
- package/dist/extensions/memory/episodic/schema.d.ts +74 -0
- package/dist/extensions/memory/episodic/schema.d.ts.map +1 -0
- package/dist/extensions/memory/episodic/schema.js +58 -0
- package/dist/extensions/memory/episodic/schema.js.map +1 -0
- package/dist/extensions/memory/episodic/store.d.ts +31 -0
- package/dist/extensions/memory/episodic/store.d.ts.map +1 -0
- package/dist/extensions/memory/episodic/store.js +147 -0
- package/dist/extensions/memory/episodic/store.js.map +1 -0
- package/dist/extensions/memory/episodic/types.d.ts +35 -0
- package/dist/extensions/memory/episodic/types.d.ts.map +1 -0
- package/dist/extensions/memory/episodic/types.js +2 -0
- package/dist/extensions/memory/episodic/types.js.map +1 -0
- package/dist/extensions/memory/errors.d.ts +19 -0
- package/dist/extensions/memory/errors.d.ts.map +1 -0
- package/dist/extensions/memory/errors.js +37 -0
- package/dist/extensions/memory/errors.js.map +1 -0
- package/dist/extensions/memory/index.d.ts +13 -0
- package/dist/extensions/memory/index.d.ts.map +1 -0
- package/dist/extensions/memory/index.js +10 -0
- package/dist/extensions/memory/index.js.map +1 -0
- package/dist/extensions/memory/memory.router.d.ts +17 -0
- package/dist/extensions/memory/memory.router.d.ts.map +1 -0
- package/dist/extensions/memory/memory.router.js +289 -0
- package/dist/extensions/memory/memory.router.js.map +1 -0
- package/dist/extensions/memory/procedural/schema.d.ts +88 -0
- package/dist/extensions/memory/procedural/schema.d.ts.map +1 -0
- package/dist/extensions/memory/procedural/schema.js +67 -0
- package/dist/extensions/memory/procedural/schema.js.map +1 -0
- package/dist/extensions/memory/procedural/store.d.ts +20 -0
- package/dist/extensions/memory/procedural/store.d.ts.map +1 -0
- package/dist/extensions/memory/procedural/store.js +125 -0
- package/dist/extensions/memory/procedural/store.js.map +1 -0
- package/dist/extensions/memory/procedural/types.d.ts +26 -0
- package/dist/extensions/memory/procedural/types.d.ts.map +1 -0
- package/dist/extensions/memory/procedural/types.js +2 -0
- package/dist/extensions/memory/procedural/types.js.map +1 -0
- package/dist/extensions/memory/router.d.ts +23 -0
- package/dist/extensions/memory/router.d.ts.map +1 -0
- package/dist/extensions/memory/router.js +76 -0
- package/dist/extensions/memory/router.js.map +1 -0
- package/dist/extensions/memory/social/schema.d.ts +34 -0
- package/dist/extensions/memory/social/schema.d.ts.map +1 -0
- package/dist/extensions/memory/social/schema.js +34 -0
- package/dist/extensions/memory/social/schema.js.map +1 -0
- package/dist/extensions/memory/social/store.d.ts +20 -0
- package/dist/extensions/memory/social/store.d.ts.map +1 -0
- package/dist/extensions/memory/social/store.js +142 -0
- package/dist/extensions/memory/social/store.js.map +1 -0
- package/dist/extensions/memory/social/types.d.ts +19 -0
- package/dist/extensions/memory/social/types.d.ts.map +1 -0
- package/dist/extensions/memory/social/types.js +2 -0
- package/dist/extensions/memory/social/types.js.map +1 -0
- package/dist/extensions/reflection/errors.d.ts +17 -0
- package/dist/extensions/reflection/errors.d.ts.map +1 -0
- package/dist/extensions/reflection/errors.js +33 -0
- package/dist/extensions/reflection/errors.js.map +1 -0
- package/dist/extensions/reflection/index.d.ts +7 -0
- package/dist/extensions/reflection/index.d.ts.map +1 -0
- package/dist/extensions/reflection/index.js +6 -0
- package/dist/extensions/reflection/index.js.map +1 -0
- package/dist/extensions/reflection/reflection.router.d.ts +8 -0
- package/dist/extensions/reflection/reflection.router.d.ts.map +1 -0
- package/dist/extensions/reflection/reflection.router.js +195 -0
- package/dist/extensions/reflection/reflection.router.js.map +1 -0
- package/dist/extensions/reflection/reflection.service.d.ts +20 -0
- package/dist/extensions/reflection/reflection.service.d.ts.map +1 -0
- package/dist/extensions/reflection/reflection.service.js +69 -0
- package/dist/extensions/reflection/reflection.service.js.map +1 -0
- package/dist/extensions/reflection/schema.d.ts +508 -0
- package/dist/extensions/reflection/schema.d.ts.map +1 -0
- package/dist/extensions/reflection/schema.js +200 -0
- package/dist/extensions/reflection/schema.js.map +1 -0
- package/dist/extensions/reflection/store.d.ts +22 -0
- package/dist/extensions/reflection/store.d.ts.map +1 -0
- package/dist/extensions/reflection/store.js +326 -0
- package/dist/extensions/reflection/store.js.map +1 -0
- package/dist/extensions/reflection/types.d.ts +220 -0
- package/dist/extensions/reflection/types.d.ts.map +1 -0
- package/dist/extensions/reflection/types.js +2 -0
- package/dist/extensions/reflection/types.js.map +1 -0
- package/dist/extensions/reputation/errors.d.ts +21 -0
- package/dist/extensions/reputation/errors.d.ts.map +1 -0
- package/dist/extensions/reputation/errors.js +41 -0
- package/dist/extensions/reputation/errors.js.map +1 -0
- package/dist/extensions/reputation/index.d.ts +6 -0
- package/dist/extensions/reputation/index.d.ts.map +1 -0
- package/dist/extensions/reputation/index.js +5 -0
- package/dist/extensions/reputation/index.js.map +1 -0
- package/dist/extensions/reputation/schema.d.ts +157 -0
- package/dist/extensions/reputation/schema.d.ts.map +1 -0
- package/dist/extensions/reputation/schema.js +96 -0
- package/dist/extensions/reputation/schema.js.map +1 -0
- package/dist/extensions/reputation/store.d.ts +21 -0
- package/dist/extensions/reputation/store.d.ts.map +1 -0
- package/dist/extensions/reputation/store.js +421 -0
- package/dist/extensions/reputation/store.js.map +1 -0
- package/dist/extensions/reputation/types.d.ts +106 -0
- package/dist/extensions/reputation/types.d.ts.map +1 -0
- package/dist/extensions/reputation/types.js +2 -0
- package/dist/extensions/reputation/types.js.map +1 -0
- package/dist/extensions/social/errors.d.ts +25 -0
- package/dist/extensions/social/errors.d.ts.map +1 -0
- package/dist/extensions/social/errors.js +49 -0
- package/dist/extensions/social/errors.js.map +1 -0
- package/dist/extensions/social/index.d.ts +7 -0
- package/dist/extensions/social/index.d.ts.map +1 -0
- package/dist/extensions/social/index.js +6 -0
- package/dist/extensions/social/index.js.map +1 -0
- package/dist/extensions/social/schema.d.ts +421 -0
- package/dist/extensions/social/schema.d.ts.map +1 -0
- package/dist/extensions/social/schema.js +154 -0
- package/dist/extensions/social/schema.js.map +1 -0
- package/dist/extensions/social/social.router.d.ts +8 -0
- package/dist/extensions/social/social.router.d.ts.map +1 -0
- package/dist/extensions/social/social.router.js +199 -0
- package/dist/extensions/social/social.router.js.map +1 -0
- package/dist/extensions/social/social.service.d.ts +27 -0
- package/dist/extensions/social/social.service.d.ts.map +1 -0
- package/dist/extensions/social/social.service.js +93 -0
- package/dist/extensions/social/social.service.js.map +1 -0
- package/dist/extensions/social/store.d.ts +19 -0
- package/dist/extensions/social/store.d.ts.map +1 -0
- package/dist/extensions/social/store.js +382 -0
- package/dist/extensions/social/store.js.map +1 -0
- package/dist/extensions/social/types.d.ts +292 -0
- package/dist/extensions/social/types.d.ts.map +1 -0
- package/dist/extensions/social/types.js +2 -0
- package/dist/extensions/social/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/migrator/index.d.ts +3 -0
- package/dist/migrator/index.d.ts.map +1 -0
- package/dist/migrator/index.js +2 -0
- package/dist/migrator/index.js.map +1 -0
- package/dist/migrator/migrator.d.ts +16 -0
- package/dist/migrator/migrator.d.ts.map +1 -0
- package/dist/migrator/migrator.js +225 -0
- package/dist/migrator/migrator.js.map +1 -0
- package/dist/migrator/types.d.ts +9 -0
- package/dist/migrator/types.d.ts.map +1 -0
- package/dist/migrator/types.js +2 -0
- package/dist/migrator/types.js.map +1 -0
- package/dist/soma.d.ts +66 -0
- package/dist/soma.d.ts.map +1 -0
- package/dist/soma.js +112 -0
- package/dist/soma.js.map +1 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +2 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/types/database.d.ts +8 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/database.js +2 -0
- package/dist/types/database.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/embedder.d.ts +13 -0
- package/dist/utils/embedder.d.ts.map +1 -0
- package/dist/utils/embedder.js +97 -0
- package/dist/utils/embedder.js.map +1 -0
- package/dist/utils/forgetting.d.ts +22 -0
- package/dist/utils/forgetting.d.ts.map +1 -0
- package/dist/utils/forgetting.js +29 -0
- package/dist/utils/forgetting.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +12 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/validation.d.ts +10 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +9 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +111 -0
- package/schema/clickhouse/01-episodes.sql +50 -0
- package/schema/clickhouse/02-learning-events.sql +37 -0
- package/schema/clickhouse/03-trust-history.sql +15 -0
- package/schema/clickhouse/04-reflection-events.sql +12 -0
- package/schema/clickhouse/05-emotional-events.sql +14 -0
- package/schema/postgres/001_create_schema.sql +11 -0
- package/schema/postgres/002_create_agent_identities.sql +63 -0
- package/schema/postgres/003_create_identity_evolution_log.sql +21 -0
- package/schema/postgres/004_create_agent_cards.sql +29 -0
- package/schema/postgres/005_create_memory_tables.sql +32 -0
- package/schema/postgres/006_create_learning_tables.sql +119 -0
- package/schema/postgres/007_create_reputation_tables.sql +27 -0
- package/schema/postgres/008_create_social_tables.sql +43 -0
- package/schema/postgres/009_create_reflection_tables.sql +54 -0
- package/schema/postgres/010_create_emotional_tables.sql +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Tensai
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Soma Protocol
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](tsconfig.json)
|
|
5
|
+
[](https://bun.sh)
|
|
6
|
+
|
|
7
|
+
Русский | [English](README_EN.md) | [中文](README_ZH.md)
|
|
8
|
+
|
|
9
|
+
TypeScript-библиотека для создания AI-агентов как полноценных личностей — с идентичностью, многоуровневой памятью, обучением, репутацией, социальными связями, эмоциональным контекстом и саморефлексией.
|
|
10
|
+
|
|
11
|
+
## Что это
|
|
12
|
+
|
|
13
|
+
Soma — не приложение, а протокол и библиотека, которую потребители импортируют в свои проекты. Каждый агент обладает:
|
|
14
|
+
|
|
15
|
+
- **Идентичностью** — персона, вектор личности, настроение, стиль коммуникации, эволюция во времени
|
|
16
|
+
- **Памятью** — 4 уровня: эпизодическая (события), процедурная (паттерны действий), социальная (отношения с другими агентами), семантическая (векторный поиск)
|
|
17
|
+
- **Обучением** — передача знаний между агентами, наблюдательное обучение, дистилляция знаний из опыта
|
|
18
|
+
- **Репутацией** — байесовский доверительный скор, домен-специфичное доверие, временной распад, система эндорсментов
|
|
19
|
+
- **Социальными связями** — отношения (11 типов), команды, общие контексты
|
|
20
|
+
- **Эмоциональным интеллектом** — детекция эмоций партнёра, адаптация тона и поведения
|
|
21
|
+
- **Саморефлексией** — инсайты, ретроспективы, профиль самосознания (сильные/слабые стороны, слепые зоны, предубеждения)
|
|
22
|
+
|
|
23
|
+
## Архитектура
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
graph TB
|
|
27
|
+
subgraph L3["Layer 3: Social Intelligence"]
|
|
28
|
+
L3_SOCIAL["Social<br/><small>teams, relationships</small>"]
|
|
29
|
+
L3_LEARN["Learning<br/><small>teach, learn, observe</small>"]
|
|
30
|
+
L3_REP["Reputation<br/><small>trust, endorse, tiers</small>"]
|
|
31
|
+
L3_REF["Reflection<br/><small>insights, retrospectives</small>"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
subgraph L2["Layer 2: Identity & Memory"]
|
|
35
|
+
L2_ID["Identity<br/><small>persona, state, evolve</small>"]
|
|
36
|
+
L2_EPI["Episodic Memory<br/><small>events, recall</small>"]
|
|
37
|
+
L2_PROC["Procedural Memory<br/><small>patterns, adapt</small>"]
|
|
38
|
+
L2_EMO["Emotional<br/><small>mood, detect, adapt</small>"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
subgraph L1["Layer 1: Transport"]
|
|
42
|
+
L1_RPC["JSON-RPC<br/><small>planned</small>"]
|
|
43
|
+
L1_GRPC["gRPC<br/><small>planned</small>"]
|
|
44
|
+
L1_WS["WebSocket<br/><small>planned</small>"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
L3 --> L2
|
|
48
|
+
L2 --> L1
|
|
49
|
+
|
|
50
|
+
style L3 fill:#1a1a2e,stroke:#e94560,color:#fff
|
|
51
|
+
style L2 fill:#16213e,stroke:#0f3460,color:#fff
|
|
52
|
+
style L1 fill:#0f3460,stroke:#533483,color:#fff
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Паттерн: Store → Service → Router
|
|
56
|
+
|
|
57
|
+
Каждое расширение следует единой архитектуре:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
extension/
|
|
61
|
+
├── types.ts # TypeScript-интерфейсы
|
|
62
|
+
├── schema.ts # Zod v4 схемы валидации
|
|
63
|
+
├── store.ts # Доступ к БД (сырой SQL)
|
|
64
|
+
├── *.service.ts # Бизнес-логика
|
|
65
|
+
├── *.router.ts # HTTP-обработчики (Request → Response)
|
|
66
|
+
└── errors.ts # Кастомные ошибки
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- **Store** — принимает `Database` интерфейс, выполняет SQL-запросы
|
|
70
|
+
- **Service** — бизнес-логика поверх store
|
|
71
|
+
- **Router** — валидирует входящие запросы через Zod, вызывает service, возвращает ответ
|
|
72
|
+
|
|
73
|
+
### Двойное хранилище (Dual-Store)
|
|
74
|
+
|
|
75
|
+
```mermaid
|
|
76
|
+
graph LR
|
|
77
|
+
subgraph PostgreSQL["PostgreSQL (state)"]
|
|
78
|
+
PG_TABLES["identities\nprocedures\nteams\nrelationships\nreputation"]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
subgraph ClickHouse["ClickHouse (events)"]
|
|
82
|
+
CH_TABLES["episodes\nlearning\ntrust history\nreflections\nemotions"]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
subgraph App["Application"]
|
|
86
|
+
Store["Store"]
|
|
87
|
+
EventBus["EventBus\n(batched)"]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
Store -->|"read/write"| PostgreSQL
|
|
91
|
+
Store -->|"emit events"| EventBus
|
|
92
|
+
EventBus -->|"batch flush"| ClickHouse
|
|
93
|
+
ClickHouse -.->|"query"| Store
|
|
94
|
+
|
|
95
|
+
style PostgreSQL fill:#336791,stroke:#fff,color:#fff
|
|
96
|
+
style ClickHouse shade:dark,fill:#fadb14,stroke:#333,color:#333
|
|
97
|
+
style App fill:#1a1a2e,stroke:#e94560,color:#fff
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- **PostgreSQL** — транзакционное состояние (идентичности, процедуры, команды, репутация)
|
|
101
|
+
- **ClickHouse** — append-only лог событий (эпизоды, обучение, история доверия)
|
|
102
|
+
- **EventBus** — батчит события и сливает в ClickHouse пакетами
|
|
103
|
+
|
|
104
|
+
### pgvector для поиска похожих агентов
|
|
105
|
+
|
|
106
|
+
Вектор личности хранится как `vector(128)` в PostgreSQL с pgvector расширением. Поиск похожих агентов через косинусное расстояние `<=>`:
|
|
107
|
+
|
|
108
|
+
```sql
|
|
109
|
+
SELECT agent_id, personality_vector <=> $1 AS distance
|
|
110
|
+
FROM agent_persona
|
|
111
|
+
ORDER BY distance ASC
|
|
112
|
+
LIMIT $2
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Расширения
|
|
116
|
+
|
|
117
|
+
### Identity
|
|
118
|
+
|
|
119
|
+
Управление идентичностью агента — персона, состояние, эволюция.
|
|
120
|
+
|
|
121
|
+
| Компонент | Описание |
|
|
122
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------ |
|
|
123
|
+
| `Persona` | Имя, описание, ценности (1–10), стиль коммуникации, домены экспертизы, вектор личности (128-dim) |
|
|
124
|
+
| `AgentState` | Настроение (15 вариантов), энергия, уверенность, скорость обучения, счётчик взаимодействий |
|
|
125
|
+
| `AgentMeta` | Дата создания, версия, родительский агент, лог эволюции |
|
|
126
|
+
| `generateInstructions()` | Генерирует system prompt из состояния агента для LLM |
|
|
127
|
+
|
|
128
|
+
15 настроений: `neutral`, `focused`, `creative`, `analytical`, `supportive`, `energized`, `calm`, `frustrated`, `confused`, `excited`, `worried`, `satisfied`, `disappointed`, `curious`, `tired`
|
|
129
|
+
|
|
130
|
+
5 стилей коммуникации: `formal`, `casual`, `technical`, `empathetic`, `adaptive`
|
|
131
|
+
|
|
132
|
+
### Memory
|
|
133
|
+
|
|
134
|
+
4-уровневая система памяти:
|
|
135
|
+
|
|
136
|
+
| Уровень | Тип | Хранилище | Описание |
|
|
137
|
+
| ---------- | ------------- | ---------------- | -------------------------------------------------------------------------- |
|
|
138
|
+
| Semantic | Embeddings | ClickHouse | Векторный поиск через cosineDistance |
|
|
139
|
+
| Episodic | Events | ClickHouse | События с контекстом, действиями, исходами, эмоциональным состоянием |
|
|
140
|
+
| Procedural | Patterns | PostgreSQL/JSONB | Паттерны действий с триггерами, шагами, условиями, метриками эффективности |
|
|
141
|
+
| Social | Relationships | PostgreSQL | Доверие, предпочтения, история взаимодействий между парами агентов |
|
|
142
|
+
|
|
143
|
+
**Забывание**: экспоненциальный распад с полувыведением = importance × 30 дней. Релевантность = 0.4×recency + 0.35×importance + 0.25×confidence.
|
|
144
|
+
|
|
145
|
+
### Learning
|
|
146
|
+
|
|
147
|
+
Система обучения агентов:
|
|
148
|
+
|
|
149
|
+
- **Learning Events** — записи о том, что агент узнал (контекст, источник, тип, конфиденциальность)
|
|
150
|
+
- **Teaching Offers** — предложения обучения между агентами (accept/decline с причинами)
|
|
151
|
+
- **Observational Learning** — обучение наблюдением за другими агентами (с согласия)
|
|
152
|
+
- **Knowledge Distillation** — дистилляция знаний из эпизодов и процедур в переносимые инсайты
|
|
153
|
+
- **Learning Scorecard** — метрики роста, вклада, прогресса обучения
|
|
154
|
+
- **Curriculum** — рекомендации что изучать дальше
|
|
155
|
+
|
|
156
|
+
### Reputation
|
|
157
|
+
|
|
158
|
+
Система репутации и доверия:
|
|
159
|
+
|
|
160
|
+
- **Trust Relationships** — байесовское обновление доверия между агентами
|
|
161
|
+
- **Temporal Decay** — доверие распадается со временем без подтверждения
|
|
162
|
+
- **Domain-Specific Trust** — доверие в разных контекстах (code_review, debugging, design)
|
|
163
|
+
- **Reputation Tiers**: unrated → novice → developing → competent → proficient → expert → master
|
|
164
|
+
- **Endorsements** — подтверждения от других агентов с весом, зависящим от уровня эндорсера
|
|
165
|
+
- **Awards** — система наград с автоматическим определением
|
|
166
|
+
|
|
167
|
+
### Emotional
|
|
168
|
+
|
|
169
|
+
Эмоциональный контекст и адаптация:
|
|
170
|
+
|
|
171
|
+
- **Internal State** — внутреннее эмоциональное состояние агента (tone, energy, engagement)
|
|
172
|
+
- **Detected State** — детекция эмоций партнёра по ключевым словам (frustration, urgency, appreciation, confusion)
|
|
173
|
+
- **Adaptation** — адаптация коммуникации: корректировка тона, уровня детализации, терпеливости
|
|
174
|
+
- **Feedback Loop** — обработка обратной связи об эмоциональном воздействии
|
|
175
|
+
|
|
176
|
+
10 тонов: `neutral`, `warm`, `formal`, `playful`, `serious`, `encouraging`, `cautious`, `bold`, `apologetic`, `enthusiastic`
|
|
177
|
+
|
|
178
|
+
### Social
|
|
179
|
+
|
|
180
|
+
Социальная структура и командная работа:
|
|
181
|
+
|
|
182
|
+
- **Relationships** — 11 типов: collaborator, mentor, mentee, competitor, partner, subordinate, supervisor, peer, acquaintance, rival, former_teammate
|
|
183
|
+
- **Teams** — состав, роли, иерархия, культура, метрики
|
|
184
|
+
- **Shared Context** — общее состояние, знания, координация, история между агентами
|
|
185
|
+
|
|
186
|
+
### Reflection
|
|
187
|
+
|
|
188
|
+
Саморефлексия и ретроспективы:
|
|
189
|
+
|
|
190
|
+
- **Reflections** — триггеры, анализ, инсайты, действия (с приоритетом и статусом)
|
|
191
|
+
- **Team Retrospectives** — went_well, to_improve, action_items с assignee и дедлайнами
|
|
192
|
+
- **Self-Awareness Profile** — сильные/слабые стороны, слепые зоны, предубеждения, области роста, эмоциональные паттерны, стиль коммуникации, рабочие предпочтения
|
|
193
|
+
|
|
194
|
+
## Утилиты
|
|
195
|
+
|
|
196
|
+
| Утилита | Файл | Описание |
|
|
197
|
+
| ------------------------------ | ------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
198
|
+
| `createEmbedder()` | `src/utils/embedder.ts` | Мульти-провайдерный сервис эмбеддингов (openai, cohere, voyage, custom). 1536 dim по умолчанию |
|
|
199
|
+
| `calculateRecallProbability()` | `src/utils/forgetting.ts` | Экспоненциальный распад памяти |
|
|
200
|
+
| `recencyScore()` | `src/utils/forgetting.ts` | Оценка свежести |
|
|
201
|
+
| `relevanceScore()` | `src/utils/forgetting.ts` | Композитная оценка релевантности |
|
|
202
|
+
| `validateSchema()` | `src/utils/validation.ts` | Обёртка валидации Zod |
|
|
203
|
+
|
|
204
|
+
## Database
|
|
205
|
+
|
|
206
|
+
### PostgreSQL (миграции: `schema/postgres/`)
|
|
207
|
+
|
|
208
|
+
6 схем: `soma`, `learning`, `reputation`, `social`, `reflection`, `emotional`
|
|
209
|
+
|
|
210
|
+
| Миграция | Таблицы | Ключевые особенности |
|
|
211
|
+
| -------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
|
|
212
|
+
| 001 | `migrations` | Трекер миграций |
|
|
213
|
+
| 002 | `agent_identities`, `agent_persona`, `agent_state`, `agent_meta`, `agent_core_values`, `agent_expertise_domains` | pgvector `vector(128)`, ivfflat индекс |
|
|
214
|
+
| 003 | `identity_evolution_log` | UUID PK, составной индекс |
|
|
215
|
+
| 004 | `agent_cards`, `agent_capabilities` | A2A-совместимые карточки агентов |
|
|
216
|
+
| 005 | `procedures`, `social_memories` | JSONB колонки, GIN индексы |
|
|
217
|
+
| 006 | `learning_events`, `teaching_offers`, `knowledge_transfers`, `observations`, `distillations` | CHECK constraints, JSONB массивы |
|
|
218
|
+
| 007 | `trust_relationships`, `agent_reputations` | Составной PK (tenant_id, truster, trustee) |
|
|
219
|
+
| 008 | `relationships`, `teams`, `team_members` | Unique индекс на парах агентов |
|
|
220
|
+
| 009 | `reflections`, `retrospectives`, `insights`, `self_awareness_profiles` | GIN индекс на trigger JSONB |
|
|
221
|
+
| 010 | `contexts`, `history` | JSONB контекст |
|
|
222
|
+
|
|
223
|
+
### ClickHouse (миграции: `schema/clickhouse/`)
|
|
224
|
+
|
|
225
|
+
| Файл | Таблицы | Engine | TTL |
|
|
226
|
+
| ------------------------ | --------------------------------- | ------------------ | -------------------- |
|
|
227
|
+
| 01-episodes.sql | `episodes` | ReplacingMergeTree | partitioned by month |
|
|
228
|
+
| 02-learning-events.sql | `learning_events`, `observations` | ReplacingMergeTree | partitioned by month |
|
|
229
|
+
| 03-trust-history.sql | `trust_history` | MergeTree | 365 days |
|
|
230
|
+
| 04-reflection-events.sql | `reflection_events` | MergeTree | 365 days |
|
|
231
|
+
| 05-emotional-events.sql | `emotional_events` | MergeTree | 365 days |
|
|
232
|
+
|
|
233
|
+
## Адаптеры базы данных
|
|
234
|
+
|
|
235
|
+
Все store принимают `Database` интерфейс. 5 адаптеров в `src/adapters/`:
|
|
236
|
+
|
|
237
|
+
| Адаптер | Файл | Драйвер |
|
|
238
|
+
| -------- | ------------- | ------------------------------------ |
|
|
239
|
+
| Bun | `bun.ts` | `Bun.sql` (tagged template literals) |
|
|
240
|
+
| pg | `pg.ts` | node-postgres |
|
|
241
|
+
| postgres | `postgres.ts` | postgres.js |
|
|
242
|
+
| Drizzle | `drizzle.ts` | Drizzle ORM |
|
|
243
|
+
| TypeORM | `typeorm.ts` | TypeORM |
|
|
244
|
+
|
|
245
|
+
## Статус реализации
|
|
246
|
+
|
|
247
|
+
### Реализовано
|
|
248
|
+
|
|
249
|
+
| Расширение | Файлы | Описание |
|
|
250
|
+
| ------------------- | ----- | ---------------------------------------------------------------- |
|
|
251
|
+
| Identity | 7 | Полная реализация: store, service, router, generate-instructions |
|
|
252
|
+
| Memory (Episodic) | 3 | Store с EventBus + ClickHouse, векторный recall |
|
|
253
|
+
| Memory (Procedural) | 3 | Store с PostgreSQL/JSONB, наследование процедур |
|
|
254
|
+
| Memory (Social) | 3 | Store с управлением доверием и предпочтениями |
|
|
255
|
+
| Learning | 9 | Store, observation, distiller, scorecard, router |
|
|
256
|
+
| Reputation | 5 | Store с байесовским обновлением, temporal decay, endorsement |
|
|
257
|
+
| Emotional | 7 | Store, service с детекцией эмоций, router |
|
|
258
|
+
| Reflection | 7 | Store, service, router с ретроспективами |
|
|
259
|
+
| Social | 7 | Store, service, router с командами |
|
|
260
|
+
| Events | 3 | EventBus + ClickHouse client |
|
|
261
|
+
| Utils | 5 | Embedder, forgetting, validation, json |
|
|
262
|
+
| Adapters | 6 | 5 адаптеров БД |
|
|
263
|
+
| Migrатор | 3 | Миграции PostgreSQL |
|
|
264
|
+
|
|
265
|
+
### Планируется
|
|
266
|
+
|
|
267
|
+
| Компонент | Статус |
|
|
268
|
+
| ------------------------------------- | ----------------- |
|
|
269
|
+
| Transport (JSON-RPC, gRPC, WebSocket) | Пустые директории |
|
|
270
|
+
| Server / Client | Пустые директории |
|
|
271
|
+
| Proto definitions | Пустая директория |
|
|
272
|
+
| Tools extension | Пустая директория |
|
|
273
|
+
|
|
274
|
+
## Стек
|
|
275
|
+
|
|
276
|
+
- **Runtime**: Bun
|
|
277
|
+
- **Язык**: TypeScript (strict, `noUncheckedIndexedAccess`, `verbatimModuleSyntax`)
|
|
278
|
+
- **Валидация**: Zod v4
|
|
279
|
+
- **Векторный поиск**: pgvector (PostgreSQL)
|
|
280
|
+
- **Аналитика**: ClickHouse (append-only events)
|
|
281
|
+
- **Эмбеддинги**: OpenAI, Cohere, Voyage, кастомные провайдеры
|
|
282
|
+
|
|
283
|
+
## Команды
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
bun test # все тесты
|
|
287
|
+
bun test tests/unit/identity.test.ts # один файл
|
|
288
|
+
bun x tsc --noEmit # типчекинг
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Структура проекта
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
src/
|
|
295
|
+
types/ # Database интерфейс
|
|
296
|
+
utils/ # embedder, forgetting, validation
|
|
297
|
+
extensions/
|
|
298
|
+
identity/ # идентичность агента
|
|
299
|
+
memory/ # 4-уровневая память
|
|
300
|
+
episodic/ # эпизодическая память
|
|
301
|
+
procedural/ # процедурная память
|
|
302
|
+
social/ # социальная память
|
|
303
|
+
learning/ # обучение и передача знаний
|
|
304
|
+
reputation/ # репутация и доверие
|
|
305
|
+
emotional/ # эмоциональный контекст
|
|
306
|
+
reflection/ # саморефлексия
|
|
307
|
+
social/ # команды и отношения
|
|
308
|
+
events/ # EventBus + ClickHouse
|
|
309
|
+
tools/ # (planned)
|
|
310
|
+
adapters/ # 5 адаптеров БД
|
|
311
|
+
migrator/ # миграции PostgreSQL
|
|
312
|
+
agent/ # интерфейсы агента
|
|
313
|
+
transport/ # (planned) JSON-RPC, gRPC, WebSocket
|
|
314
|
+
server/ # (planned)
|
|
315
|
+
client/ # (planned)
|
|
316
|
+
schema/
|
|
317
|
+
postgres/ # 10 DDL миграций
|
|
318
|
+
clickhouse/ # 5 DDL файлов
|
|
319
|
+
tests/
|
|
320
|
+
unit/ # 21 тест-файл (7 расширений)
|
|
321
|
+
integration-test/ # Docker Compose (PostgreSQL + ClickHouse)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Лицензия
|
|
325
|
+
|
|
326
|
+
[Apache License 2.0](LICENSE)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Database } from '../types/database';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter for Bun.sql (tagged template literal)
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const db = createBunDatabase(Bun.sql);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare function createBunDatabase(sql: typeof Bun.sql): Database;
|
|
10
|
+
//# sourceMappingURL=bun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/adapters/bun.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,GAAG,GAAG,QAAQ,CAM/D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter for Bun.sql (tagged template literal)
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* const db = createBunDatabase(Bun.sql);
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export function createBunDatabase(sql) {
|
|
9
|
+
return {
|
|
10
|
+
async query(sqlStr, params) {
|
|
11
|
+
return sql.unsafe(sqlStr, params ?? []);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.js","sourceRoot":"","sources":["../../src/adapters/bun.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAmB;IACjD,OAAO;QACH,KAAK,CAAC,KAAK,CAAI,MAAc,EAAE,MAAkB;YAC7C,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAiB,CAAC;QAC5D,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Database } from '../types/database';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter for Drizzle ORM
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { drizzle } from 'drizzle-orm/node-postgres';
|
|
7
|
+
* const db = createDrizzleDatabase(drizzle(pool));
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDrizzleDatabase(db: {
|
|
11
|
+
execute: (query: {
|
|
12
|
+
getSQL: () => string;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
rows: unknown[];
|
|
15
|
+
}>;
|
|
16
|
+
}): Database;
|
|
17
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE;IACtC,OAAO,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;CAC9E,GAAG,QAAQ,CAWX"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter for Drizzle ORM
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { drizzle } from 'drizzle-orm/node-postgres';
|
|
6
|
+
* const db = createDrizzleDatabase(drizzle(pool));
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export function createDrizzleDatabase(db) {
|
|
10
|
+
return {
|
|
11
|
+
async query(sqlStr, params) {
|
|
12
|
+
// Drizzle uses parameters in the format $1, $2, ...
|
|
13
|
+
// Convert to Drizzle format
|
|
14
|
+
const result = await db.execute({
|
|
15
|
+
getSQL: () => sqlStr,
|
|
16
|
+
});
|
|
17
|
+
return result.rows;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.js","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAErC;IACG,OAAO;QACH,KAAK,CAAC,KAAK,CAAI,MAAc,EAAE,MAAkB;YAC7C,oDAAoD;YACpD,4BAA4B;YAC5B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC;gBAC5B,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;aACvB,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,IAAW,CAAC;QAC9B,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBunDatabase } from './bun';
|
|
2
|
+
export { createPostgresDatabase } from './postgres';
|
|
3
|
+
export { createPgDatabase } from './pg';
|
|
4
|
+
export { createDrizzleDatabase } from './drizzle';
|
|
5
|
+
export { createTypeormDatabase } from './typeorm';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBunDatabase } from './bun';
|
|
2
|
+
export { createPostgresDatabase } from './postgres';
|
|
3
|
+
export { createPgDatabase } from './pg';
|
|
4
|
+
export { createDrizzleDatabase } from './drizzle';
|
|
5
|
+
export { createTypeormDatabase } from './typeorm';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Database } from '../types/database';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter for node-postgres (pg)
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Pool } from 'pg';
|
|
7
|
+
* const pool = new Pool({ connectionString: 'postgres://...' });
|
|
8
|
+
* const db = createPgDatabase(pool);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function createPgDatabase(pool: {
|
|
12
|
+
query: (sql: string, params?: unknown[]) => Promise<{
|
|
13
|
+
rows: unknown[];
|
|
14
|
+
}>;
|
|
15
|
+
}): Database;
|
|
16
|
+
//# sourceMappingURL=pg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/adapters/pg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;CAC5E,GAAG,QAAQ,CAOX"}
|