@sidurijs/core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/dist/adversarial.test.js +27 -19
- package/dist/chat-contract.d.ts +9 -0
- package/dist/cognition-planner.d.ts +2 -2
- package/dist/container.d.ts +6 -4
- package/dist/container.js +1 -4
- package/dist/context-retriever.d.ts +5 -4
- package/dist/context-retriever.js +43 -25
- package/dist/conversational-teach.test.js +61 -53
- package/dist/evidence.d.ts +3 -3
- package/dist/gating.d.ts +2 -2
- package/dist/gating.js +1 -1
- package/dist/index.d.ts +43 -51
- package/dist/index.js +1 -1
- package/dist/intent-classifier.d.ts +1 -1
- package/dist/intent-classifier.js +4 -4
- package/dist/intent-classifier.test.js +1 -1
- package/dist/{memory-settler.d.ts → interaction-settler.d.ts} +12 -11
- package/dist/interaction-settler.js +173 -0
- package/dist/perception-cycle.test.js +18 -34
- package/dist/perception-pipeline.d.ts +6 -5
- package/dist/perception-pipeline.js +17 -15
- package/dist/prompt-compiler.d.ts +1 -1
- package/dist/prompt-compiler.js +11 -11
- package/dist/prompt-compiler.test.js +5 -5
- package/dist/proposals.d.ts +1 -2
- package/dist/response-envelope.d.ts +3 -3
- package/dist/response-envelope.js +5 -4
- package/dist/runtime-facades.test.js +12 -35
- package/dist/runtime.d.ts +16 -10
- package/dist/runtime.js +85 -107
- package/dist/schema-validator.test.js +3 -3
- package/dist/session-history.d.ts +3 -3
- package/dist/session-history.js +1 -1
- package/dist/siduri-db.d.ts +11 -29
- package/dist/siduri-db.js +159 -445
- package/dist/siduri-db.test.js +113 -281
- package/dist/teaching.d.ts +3 -3
- package/dist/teaching.js +1 -1
- package/package.json +7 -7
- package/dist/memory-settler.js +0 -161
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 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 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 those 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 exemplary 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 VXNUS Creative Technology Studio
|
|
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/dist/adversarial.test.js
CHANGED
|
@@ -53,38 +53,43 @@ describe('Adversarial Hardening Verification Suite (Phase 3)', () => {
|
|
|
53
53
|
validFrom: pastTime,
|
|
54
54
|
validUntil: futureTime,
|
|
55
55
|
};
|
|
56
|
-
const
|
|
56
|
+
const mockArchive = {
|
|
57
57
|
initialize: jest.fn().mockResolvedValue(undefined),
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
searchEvents: jest.fn().mockResolvedValue([{
|
|
59
|
+
id: 'evt-valid',
|
|
60
|
+
companionId: 'companion-adv',
|
|
61
|
+
sourceType: 'User',
|
|
62
|
+
occurredAt: new Date().toISOString(),
|
|
63
|
+
payload: 'favoriteColor Azure',
|
|
64
|
+
}]),
|
|
60
65
|
};
|
|
61
66
|
const runtime = new index_1.SiduriRuntime('companion-adv', { name: 'AdvCompanion' }, {
|
|
62
67
|
brain: mockBrain,
|
|
63
|
-
|
|
68
|
+
archive: mockArchive,
|
|
64
69
|
});
|
|
65
70
|
await runtime.handleUserMessage('What is my favorite color?', baseOwnerContext);
|
|
66
|
-
expect(
|
|
71
|
+
expect(mockArchive.searchEvents).toHaveBeenCalled();
|
|
67
72
|
const brainCall = mockBrain.generatePlan.mock.calls[0][0];
|
|
68
|
-
expect(brainCall.contextPrompt).toContain('
|
|
73
|
+
expect(brainCall.contextPrompt).toContain('ARCHIVE:');
|
|
74
|
+
expect(brainCall.contextPrompt).toContain('favoriteColor Azure');
|
|
69
75
|
});
|
|
70
76
|
test('companion isolation: runtime passes only companionId matching context', async () => {
|
|
71
77
|
const mockBrain = {
|
|
72
78
|
generatePlan: jest.fn().mockResolvedValue({ speech: 'OK', language: 'en' }),
|
|
73
79
|
};
|
|
74
|
-
const
|
|
80
|
+
const mockArchive = {
|
|
75
81
|
initialize: jest.fn().mockResolvedValue(undefined),
|
|
76
|
-
|
|
77
|
-
getDirectives: jest.fn().mockResolvedValue([]),
|
|
82
|
+
searchEvents: jest.fn().mockResolvedValue([]),
|
|
78
83
|
};
|
|
79
84
|
const runtime = new index_1.SiduriRuntime('companion-A', { name: 'AdvA' }, {
|
|
80
85
|
brain: mockBrain,
|
|
81
|
-
|
|
86
|
+
archive: mockArchive,
|
|
82
87
|
});
|
|
83
88
|
await runtime.handleUserMessage('Query', {
|
|
84
89
|
...baseOwnerContext,
|
|
85
90
|
companionId: 'companion-A',
|
|
86
91
|
});
|
|
87
|
-
expect(
|
|
92
|
+
expect(mockArchive.searchEvents).toHaveBeenCalledWith('companion-A', 'Query', 5);
|
|
88
93
|
});
|
|
89
94
|
});
|
|
90
95
|
// INVARIANT 2: Authority & Request Boundary
|
|
@@ -349,27 +354,30 @@ describe('Adversarial Hardening Verification Suite (Phase 3)', () => {
|
|
|
349
354
|
});
|
|
350
355
|
// INVARIANT 6: Failure Semantics & Degradation
|
|
351
356
|
describe('Invariant 6: Subsystem Failure Diagnostics & Non-Empty Propagation', () => {
|
|
352
|
-
test('
|
|
357
|
+
test('archive/self query failure surfaces diagnostic in contextPrompt and metadata', async () => {
|
|
353
358
|
const mockBrain = {
|
|
354
359
|
generatePlan: jest.fn().mockResolvedValue({ speech: 'Graceful fallback response', language: 'en' }),
|
|
355
360
|
};
|
|
356
|
-
const
|
|
361
|
+
const failingArchive = {
|
|
357
362
|
initialize: jest.fn().mockResolvedValue(undefined),
|
|
358
|
-
|
|
359
|
-
|
|
363
|
+
searchEvents: jest.fn().mockRejectedValue(new Error('Connection terminated unexpectedly')),
|
|
364
|
+
};
|
|
365
|
+
const failingSelf = {
|
|
366
|
+
getActiveDirectives: jest.fn().mockRejectedValue(new Error('Database read timeout')),
|
|
360
367
|
};
|
|
361
368
|
const runtime = new index_1.SiduriRuntime('companion-adv', { name: 'AdvCompanion' }, {
|
|
362
369
|
brain: mockBrain,
|
|
363
|
-
|
|
370
|
+
archive: failingArchive,
|
|
371
|
+
self: failingSelf,
|
|
364
372
|
});
|
|
365
373
|
const response = await runtime.handleUserMessage('Hello companion', baseOwnerContext);
|
|
366
374
|
expect(response.status).toBe('APPROVED');
|
|
367
375
|
expect(response.metadata.subsystem_diagnostics).toBeDefined();
|
|
368
|
-
expect(response.metadata.subsystem_diagnostics.
|
|
369
|
-
expect(response.metadata.subsystem_diagnostics.
|
|
376
|
+
expect(response.metadata.subsystem_diagnostics.archive).toContain('UNAVAILABLE');
|
|
377
|
+
expect(response.metadata.subsystem_diagnostics.self_directives).toContain('UNAVAILABLE');
|
|
370
378
|
const brainCall = mockBrain.generatePlan.mock.calls[0][0];
|
|
371
379
|
expect(brainCall.contextPrompt).toContain('SUBSYSTEM STATUS (DEGRADED):');
|
|
372
|
-
expect(brainCall.contextPrompt).toContain('
|
|
380
|
+
expect(brainCall.contextPrompt).toContain('archive');
|
|
373
381
|
});
|
|
374
382
|
});
|
|
375
383
|
// INVARIANT 8: Truth Gate Admissibility vs Factuality
|
package/dist/chat-contract.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ export interface ChatResponsePlan {
|
|
|
46
46
|
export interface ChatResponseMetadata {
|
|
47
47
|
language?: string;
|
|
48
48
|
proposals?: Claim[];
|
|
49
|
+
claim_proposals?: Array<{
|
|
50
|
+
proposal_id: string;
|
|
51
|
+
subject?: string;
|
|
52
|
+
predicate?: string;
|
|
53
|
+
value?: string;
|
|
54
|
+
status: string;
|
|
55
|
+
content?: string;
|
|
56
|
+
claim_type?: string;
|
|
57
|
+
}>;
|
|
49
58
|
memory_proposals?: Array<{
|
|
50
59
|
proposal_id: string;
|
|
51
60
|
subject?: string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BrainOrgan, Message, ResponsePlan,
|
|
1
|
+
import { BrainOrgan, Message, ResponsePlan, ClaimScope } from './index';
|
|
2
2
|
export interface CognitionPlanningParams {
|
|
3
3
|
companionName: string;
|
|
4
4
|
brain?: BrainOrgan;
|
|
5
5
|
systemPrompt: string;
|
|
6
6
|
contextPrompt: string;
|
|
7
7
|
recentMessages: Message[];
|
|
8
|
-
recipient?:
|
|
8
|
+
recipient?: ClaimScope;
|
|
9
9
|
perceivedText: string;
|
|
10
10
|
}
|
|
11
11
|
/**
|
package/dist/container.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BrainOrgan,
|
|
1
|
+
import { BrainOrgan, ArchiveLedger, VoiceOrgan, KnowledgeOrgan, VisionOrgan, BehaviorOrgan, BodyOrgan, HandsOrgan, EarOrgan, ObservationOrgan, MouthOrgan, SelfRepository, EKnowledgeOrgan, OrganConfig, ActionStore, ActionPolicyEngine, ResponseGatingEngine, ExperienceDispatcher, ExperienceAdapter } from './index';
|
|
2
2
|
import { SessionHistoryManager } from './session-history';
|
|
3
3
|
import { SiduriRuntime } from './runtime';
|
|
4
4
|
export interface SiduriRuntimeConfig {
|
|
5
5
|
name: string;
|
|
6
6
|
brain?: OrganConfig | Record<string, unknown>;
|
|
7
7
|
voice?: OrganConfig | Record<string, unknown>;
|
|
8
|
-
|
|
8
|
+
archive?: OrganConfig | Record<string, unknown>;
|
|
9
9
|
knowledge?: OrganConfig | Record<string, unknown>;
|
|
10
10
|
behavior?: OrganConfig | Record<string, unknown>;
|
|
11
11
|
body?: OrganConfig | Record<string, unknown>;
|
|
@@ -26,7 +26,7 @@ export interface SiduriRuntimeConfig {
|
|
|
26
26
|
}
|
|
27
27
|
export interface RuntimeOrgans {
|
|
28
28
|
brain?: BrainOrgan;
|
|
29
|
-
|
|
29
|
+
archive?: ArchiveLedger;
|
|
30
30
|
voice?: VoiceOrgan | ExperienceAdapter;
|
|
31
31
|
knowledge?: KnowledgeOrgan;
|
|
32
32
|
vision?: VisionOrgan;
|
|
@@ -40,6 +40,8 @@ export interface RuntimeOrgans {
|
|
|
40
40
|
externalKnowledge?: EKnowledgeOrgan;
|
|
41
41
|
actionStore?: ActionStore;
|
|
42
42
|
actionPolicy?: ActionPolicyEngine;
|
|
43
|
+
memory?: any;
|
|
44
|
+
[key: string]: unknown;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* CompanionContainer manages the lifecycle, discovery, wiring, and dependency injection
|
|
@@ -56,7 +58,7 @@ export declare class CompanionContainer {
|
|
|
56
58
|
private _runtime?;
|
|
57
59
|
constructor(id: string, config: SiduriRuntimeConfig, organs?: RuntimeOrgans);
|
|
58
60
|
get brain(): BrainOrgan | undefined;
|
|
59
|
-
get
|
|
61
|
+
get archive(): ArchiveLedger | undefined;
|
|
60
62
|
get voice(): ExperienceAdapter | VoiceOrgan | undefined;
|
|
61
63
|
get knowledge(): KnowledgeOrgan | undefined;
|
|
62
64
|
get vision(): VisionOrgan | undefined;
|
package/dist/container.js
CHANGED
|
@@ -47,7 +47,7 @@ class CompanionContainer {
|
|
|
47
47
|
}
|
|
48
48
|
// Direct organ accessors
|
|
49
49
|
get brain() { return this.organs.brain; }
|
|
50
|
-
get
|
|
50
|
+
get archive() { return this.organs.archive; }
|
|
51
51
|
get voice() { return this.organs.voice; }
|
|
52
52
|
get knowledge() { return this.organs.knowledge; }
|
|
53
53
|
get vision() { return this.organs.vision; }
|
|
@@ -61,9 +61,6 @@ class CompanionContainer {
|
|
|
61
61
|
get self() { return this.organs.self; }
|
|
62
62
|
get externalKnowledge() { return this.organs.externalKnowledge; }
|
|
63
63
|
async initialize() {
|
|
64
|
-
if (this.organs.memory && typeof this.organs.memory.initialize === 'function') {
|
|
65
|
-
await this.organs.memory.initialize(this.id);
|
|
66
|
-
}
|
|
67
64
|
if (this.organs.hands && typeof this.organs.hands.listTools === 'function') {
|
|
68
65
|
const tools = await this.organs.hands.listTools();
|
|
69
66
|
for (const tool of tools) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KnowledgeOrgan,
|
|
1
|
+
import { KnowledgeOrgan, KnowledgeItem, Claim, BehaviorDirective, EvidenceRecord, ResponseCitation, RequestContext, SelfRepository, LifeDatabase, ArchiveLedger, EKnowledgeOrgan } from './index';
|
|
2
2
|
export interface ContextRetrievalParams {
|
|
3
3
|
companionId: string;
|
|
4
4
|
perceivedText: string;
|
|
@@ -7,16 +7,17 @@ export interface ContextRetrievalParams {
|
|
|
7
7
|
isContextObject: boolean;
|
|
8
8
|
shouldQueryKnowledge: boolean;
|
|
9
9
|
knowledgeQueries?: string[];
|
|
10
|
-
|
|
10
|
+
archiveQueries?: string[];
|
|
11
11
|
isSelfIdentityRequest?: boolean;
|
|
12
12
|
knowledge?: KnowledgeOrgan | LifeDatabase;
|
|
13
|
-
|
|
13
|
+
archive?: ArchiveLedger;
|
|
14
|
+
memory?: any;
|
|
14
15
|
self?: SelfRepository;
|
|
15
16
|
externalKnowledge?: EKnowledgeOrgan | KnowledgeOrgan;
|
|
16
17
|
}
|
|
17
18
|
export interface RetrievedContext {
|
|
18
19
|
knowledgeData: KnowledgeItem[];
|
|
19
|
-
|
|
20
|
+
archiveData: Claim[];
|
|
20
21
|
activeDirectives: BehaviorDirective[];
|
|
21
22
|
subsystemDiagnostics: Record<string, string>;
|
|
22
23
|
collectedEvidence: EvidenceRecord[];
|
|
@@ -7,7 +7,7 @@ const intent_classifier_1 = require("./intent-classifier");
|
|
|
7
7
|
* in a single parallel pass with graceful degradation.
|
|
8
8
|
*/
|
|
9
9
|
async function retrieveRuntimeContext(params) {
|
|
10
|
-
const { companionId, perceivedText, requestContext, role, isContextObject, shouldQueryKnowledge, knowledgeQueries,
|
|
10
|
+
const { companionId, perceivedText, requestContext, role, isContextObject, shouldQueryKnowledge, knowledgeQueries, archiveQueries, isSelfIdentityRequest, knowledge, archive, memory, self, externalKnowledge, } = params;
|
|
11
11
|
const queryOptions = isContextObject
|
|
12
12
|
? {
|
|
13
13
|
limit: 5,
|
|
@@ -31,11 +31,11 @@ async function retrieveRuntimeContext(params) {
|
|
|
31
31
|
queryCandidateSet.add(perceivedText.trim());
|
|
32
32
|
}
|
|
33
33
|
const finalKnowledgeQueries = Array.from(queryCandidateSet);
|
|
34
|
-
const
|
|
35
|
-
?
|
|
34
|
+
const archiveQueryToRun = (archiveQueries && archiveQueries.length > 0 && archiveQueries[0])
|
|
35
|
+
? archiveQueries[0]
|
|
36
36
|
: (0, intent_classifier_1.extractSearchKeywords)(perceivedText, companionId)[0] || perceivedText;
|
|
37
37
|
// 2. Query streams in parallel
|
|
38
|
-
const [knowledgeData,
|
|
38
|
+
const [knowledgeData, archiveData, selfDirectives, lifeContext, selfIdentity, selfRelationship, personality,] = await Promise.all([
|
|
39
39
|
// Stream A: External Cited Lore / Documentation
|
|
40
40
|
extKnowledge && shouldQueryKnowledge && typeof extKnowledge.search === 'function'
|
|
41
41
|
? Promise.all(finalKnowledgeQueries.map((q) => extKnowledge.search(q).catch((e) => {
|
|
@@ -46,10 +46,8 @@ async function retrieveRuntimeContext(params) {
|
|
|
46
46
|
const merged = [];
|
|
47
47
|
const seen = new Set();
|
|
48
48
|
for (const list of resultsArray) {
|
|
49
|
-
if (!Array.isArray(list))
|
|
50
|
-
continue;
|
|
51
49
|
for (const item of list) {
|
|
52
|
-
const key = item.
|
|
50
|
+
const key = item.content.slice(0, 100);
|
|
53
51
|
if (!seen.has(key)) {
|
|
54
52
|
seen.add(key);
|
|
55
53
|
merged.push(item);
|
|
@@ -59,12 +57,11 @@ async function retrieveRuntimeContext(params) {
|
|
|
59
57
|
return merged;
|
|
60
58
|
})
|
|
61
59
|
: Promise.resolve([]),
|
|
62
|
-
// Stream B:
|
|
60
|
+
// Stream B: Interaction Archive / Claims
|
|
63
61
|
memory && typeof memory.searchClaims === 'function'
|
|
64
62
|
? (async () => {
|
|
65
63
|
try {
|
|
66
|
-
|
|
67
|
-
let result = await memory.searchClaims(memoryQueryToRun, queryOptions, 5);
|
|
64
|
+
let result = await memory.searchClaims(archiveQueryToRun, queryOptions, 5);
|
|
68
65
|
if ((!result || result.length === 0) && isSelfIdentityRequest) {
|
|
69
66
|
if (typeof memory.getApprovedClaims === 'function') {
|
|
70
67
|
const approved = await memory.getApprovedClaims(companionId, 10);
|
|
@@ -93,7 +90,28 @@ async function retrieveRuntimeContext(params) {
|
|
|
93
90
|
return [];
|
|
94
91
|
}
|
|
95
92
|
})()
|
|
96
|
-
:
|
|
93
|
+
: archive && typeof archive.searchEvents === 'function'
|
|
94
|
+
? (async () => {
|
|
95
|
+
try {
|
|
96
|
+
const events = await archive.searchEvents(companionId, archiveQueryToRun, 5);
|
|
97
|
+
return (events || []).map((evt) => ({
|
|
98
|
+
id: evt.id,
|
|
99
|
+
companionId: evt.companionId,
|
|
100
|
+
subject: evt.sourceType,
|
|
101
|
+
predicate: 'event',
|
|
102
|
+
value: typeof evt.payload === 'string' ? evt.payload : JSON.stringify(evt.payload),
|
|
103
|
+
status: 'approved',
|
|
104
|
+
provenance: 'archive_ledger',
|
|
105
|
+
claimType: 'event',
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error('[SiduriRuntime] Archive search failed:', e.message);
|
|
110
|
+
subsystemDiagnostics['archive'] = `UNAVAILABLE: ${e.message}`;
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
})()
|
|
114
|
+
: Promise.resolve([]),
|
|
97
115
|
// Stream C: Active Directives from Self (or fallback Memory)
|
|
98
116
|
self && typeof self.getActiveDirectives === 'function'
|
|
99
117
|
? self.getActiveDirectives(companionId).catch((e) => {
|
|
@@ -135,7 +153,7 @@ async function retrieveRuntimeContext(params) {
|
|
|
135
153
|
? self.getPersonality(companionId).catch(() => undefined)
|
|
136
154
|
: Promise.resolve(undefined),
|
|
137
155
|
]);
|
|
138
|
-
const activeDirectives = (
|
|
156
|
+
const activeDirectives = (selfDirectives || []);
|
|
139
157
|
// Build evidence records from retrieved context streams
|
|
140
158
|
const collectedEvidence = [];
|
|
141
159
|
const citations = [];
|
|
@@ -187,19 +205,19 @@ async function retrieveRuntimeContext(params) {
|
|
|
187
205
|
}
|
|
188
206
|
}
|
|
189
207
|
}
|
|
190
|
-
// Stream B:
|
|
191
|
-
if (
|
|
192
|
-
for (const m of
|
|
193
|
-
const claimId = m.claim_id || m.id || `
|
|
194
|
-
const sourceId = m.provenance || '
|
|
195
|
-
const evId = `ev-
|
|
196
|
-
const claimPreview = m.content || `${m.subject || '
|
|
208
|
+
// Stream B: Interaction Archive
|
|
209
|
+
if (archiveData.length > 0) {
|
|
210
|
+
for (const m of archiveData) {
|
|
211
|
+
const claimId = m.claim_id || m.id || `evt-${Date.now()}`;
|
|
212
|
+
const sourceId = m.provenance || 'archive_ledger';
|
|
213
|
+
const evId = `ev-arc-${claimId}`;
|
|
214
|
+
const claimPreview = m.content || `${m.subject || 'event'} ${m.predicate || 'event'}: ${m.value || ''}`;
|
|
197
215
|
collectedEvidence.push({
|
|
198
216
|
evidenceId: evId,
|
|
199
217
|
sourceId,
|
|
200
218
|
documentId: claimId,
|
|
201
|
-
chunkId: `${m.subject || '
|
|
202
|
-
origin: '
|
|
219
|
+
chunkId: `${m.subject || 'archive'}:${m.predicate || 'event'}`,
|
|
220
|
+
origin: 'archive',
|
|
203
221
|
trust: 'configured',
|
|
204
222
|
sensitivity: 'private',
|
|
205
223
|
companionId,
|
|
@@ -208,11 +226,11 @@ async function retrieveRuntimeContext(params) {
|
|
|
208
226
|
});
|
|
209
227
|
citations.push({
|
|
210
228
|
evidenceId: evId,
|
|
211
|
-
provenance: '
|
|
229
|
+
provenance: 'archive',
|
|
212
230
|
sourceId,
|
|
213
231
|
documentId: claimId,
|
|
214
|
-
chunkId: `${m.subject || '
|
|
215
|
-
locator: `
|
|
232
|
+
chunkId: `${m.subject || 'archive'}.${m.predicate || 'event'}`,
|
|
233
|
+
locator: `archive:${claimId}`,
|
|
216
234
|
preview: claimPreview.slice(0, 300),
|
|
217
235
|
});
|
|
218
236
|
}
|
|
@@ -247,7 +265,7 @@ async function retrieveRuntimeContext(params) {
|
|
|
247
265
|
}
|
|
248
266
|
return {
|
|
249
267
|
knowledgeData,
|
|
250
|
-
|
|
268
|
+
archiveData,
|
|
251
269
|
activeDirectives,
|
|
252
270
|
subsystemDiagnostics,
|
|
253
271
|
collectedEvidence,
|