@auxiora/runtime 1.3.0 → 1.10.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/dist/enrichment/__tests__/architect-stage.test.d.ts +2 -0
- package/dist/enrichment/__tests__/architect-stage.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/architect-stage.test.js +189 -0
- package/dist/enrichment/__tests__/architect-stage.test.js.map +1 -0
- package/dist/enrichment/__tests__/integration.test.d.ts +2 -0
- package/dist/enrichment/__tests__/integration.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/integration.test.js +79 -0
- package/dist/enrichment/__tests__/integration.test.js.map +1 -0
- package/dist/enrichment/__tests__/memory-stage.test.d.ts +2 -0
- package/dist/enrichment/__tests__/memory-stage.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/memory-stage.test.js +43 -0
- package/dist/enrichment/__tests__/memory-stage.test.js.map +1 -0
- package/dist/enrichment/__tests__/mode-stage.test.d.ts +2 -0
- package/dist/enrichment/__tests__/mode-stage.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/mode-stage.test.js +139 -0
- package/dist/enrichment/__tests__/mode-stage.test.js.map +1 -0
- package/dist/enrichment/__tests__/model-identity-stage.test.d.ts +2 -0
- package/dist/enrichment/__tests__/model-identity-stage.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/model-identity-stage.test.js +74 -0
- package/dist/enrichment/__tests__/model-identity-stage.test.js.map +1 -0
- package/dist/enrichment/__tests__/pipeline.test.d.ts +2 -0
- package/dist/enrichment/__tests__/pipeline.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/pipeline.test.js +78 -0
- package/dist/enrichment/__tests__/pipeline.test.js.map +1 -0
- package/dist/enrichment/__tests__/self-awareness-stage.test.d.ts +2 -0
- package/dist/enrichment/__tests__/self-awareness-stage.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/self-awareness-stage.test.js +71 -0
- package/dist/enrichment/__tests__/self-awareness-stage.test.js.map +1 -0
- package/dist/enrichment/__tests__/types.test.d.ts +2 -0
- package/dist/enrichment/__tests__/types.test.d.ts.map +1 -0
- package/dist/enrichment/__tests__/types.test.js +31 -0
- package/dist/enrichment/__tests__/types.test.js.map +1 -0
- package/dist/enrichment/index.d.ts +8 -0
- package/dist/enrichment/index.d.ts.map +1 -0
- package/dist/enrichment/index.js +7 -0
- package/dist/enrichment/index.js.map +1 -0
- package/dist/enrichment/pipeline.d.ts +7 -0
- package/dist/enrichment/pipeline.d.ts.map +1 -0
- package/dist/enrichment/pipeline.js +29 -0
- package/dist/enrichment/pipeline.js.map +1 -0
- package/dist/enrichment/stages/architect-stage.d.ts +57 -0
- package/dist/enrichment/stages/architect-stage.d.ts.map +1 -0
- package/dist/enrichment/stages/architect-stage.js +112 -0
- package/dist/enrichment/stages/architect-stage.js.map +1 -0
- package/dist/enrichment/stages/memory-stage.d.ts +15 -0
- package/dist/enrichment/stages/memory-stage.d.ts.map +1 -0
- package/dist/enrichment/stages/memory-stage.js +19 -0
- package/dist/enrichment/stages/memory-stage.js.map +1 -0
- package/dist/enrichment/stages/mode-stage.d.ts +49 -0
- package/dist/enrichment/stages/mode-stage.d.ts.map +1 -0
- package/dist/enrichment/stages/mode-stage.js +60 -0
- package/dist/enrichment/stages/mode-stage.js.map +1 -0
- package/dist/enrichment/stages/model-identity-stage.d.ts +24 -0
- package/dist/enrichment/stages/model-identity-stage.d.ts.map +1 -0
- package/dist/enrichment/stages/model-identity-stage.js +23 -0
- package/dist/enrichment/stages/model-identity-stage.js.map +1 -0
- package/dist/enrichment/stages/self-awareness-stage.d.ts +23 -0
- package/dist/enrichment/stages/self-awareness-stage.d.ts.map +1 -0
- package/dist/enrichment/stages/self-awareness-stage.js +24 -0
- package/dist/enrichment/stages/self-awareness-stage.js.map +1 -0
- package/dist/enrichment/types.d.ts +45 -0
- package/dist/enrichment/types.d.ts.map +1 -0
- package/dist/enrichment/types.js +2 -0
- package/dist/enrichment/types.js.map +1 -0
- package/dist/index.d.ts +77 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3233 -230
- package/dist/index.js.map +1 -1
- package/dist/transparency/__tests__/collector.test.d.ts +2 -0
- package/dist/transparency/__tests__/collector.test.d.ts.map +1 -0
- package/dist/transparency/__tests__/collector.test.js +133 -0
- package/dist/transparency/__tests__/collector.test.js.map +1 -0
- package/dist/transparency/__tests__/confidence-scorer.test.d.ts +2 -0
- package/dist/transparency/__tests__/confidence-scorer.test.d.ts.map +1 -0
- package/dist/transparency/__tests__/confidence-scorer.test.js +118 -0
- package/dist/transparency/__tests__/confidence-scorer.test.js.map +1 -0
- package/dist/transparency/__tests__/source-attributor.test.d.ts +2 -0
- package/dist/transparency/__tests__/source-attributor.test.d.ts.map +1 -0
- package/dist/transparency/__tests__/source-attributor.test.js +47 -0
- package/dist/transparency/__tests__/source-attributor.test.js.map +1 -0
- package/dist/transparency/__tests__/types.test.d.ts +2 -0
- package/dist/transparency/__tests__/types.test.d.ts.map +1 -0
- package/dist/transparency/__tests__/types.test.js +62 -0
- package/dist/transparency/__tests__/types.test.js.map +1 -0
- package/dist/transparency/collector.d.ts +30 -0
- package/dist/transparency/collector.d.ts.map +1 -0
- package/dist/transparency/collector.js +79 -0
- package/dist/transparency/collector.js.map +1 -0
- package/dist/transparency/confidence-scorer.d.ts +17 -0
- package/dist/transparency/confidence-scorer.d.ts.map +1 -0
- package/dist/transparency/confidence-scorer.js +66 -0
- package/dist/transparency/confidence-scorer.js.map +1 -0
- package/dist/transparency/index.d.ts +8 -0
- package/dist/transparency/index.d.ts.map +1 -0
- package/dist/transparency/index.js +4 -0
- package/dist/transparency/index.js.map +1 -0
- package/dist/transparency/source-attributor.d.ts +10 -0
- package/dist/transparency/source-attributor.d.ts.map +1 -0
- package/dist/transparency/source-attributor.js +42 -0
- package/dist/transparency/source-attributor.js.map +1 -0
- package/dist/transparency/types.d.ts +53 -0
- package/dist/transparency/types.d.ts.map +1 -0
- package/dist/transparency/types.js +2 -0
- package/dist/transparency/types.js.map +1 -0
- package/package.json +74 -50
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { EnrichmentPipeline } from '../pipeline.js';
|
|
3
|
+
function makeCtx(overrides = {}) {
|
|
4
|
+
return {
|
|
5
|
+
basePrompt: 'base prompt',
|
|
6
|
+
userMessage: 'hello',
|
|
7
|
+
history: [],
|
|
8
|
+
channelType: 'webchat',
|
|
9
|
+
chatId: 'chat-1',
|
|
10
|
+
sessionId: 'sess-1',
|
|
11
|
+
userId: 'user-1',
|
|
12
|
+
toolsUsed: [],
|
|
13
|
+
config: {},
|
|
14
|
+
...overrides,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function makeStage(name, order, result, enabled = true) {
|
|
18
|
+
return {
|
|
19
|
+
name,
|
|
20
|
+
order,
|
|
21
|
+
enabled: () => enabled,
|
|
22
|
+
enrich: vi.fn(async (_ctx, _prompt) => result),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
describe('EnrichmentPipeline', () => {
|
|
26
|
+
it('runs stages in order and returns final prompt', async () => {
|
|
27
|
+
const pipeline = new EnrichmentPipeline();
|
|
28
|
+
pipeline.addStage(makeStage('b', 200, { prompt: 'after-b' }));
|
|
29
|
+
pipeline.addStage(makeStage('a', 100, { prompt: 'after-a' }));
|
|
30
|
+
const result = await pipeline.run(makeCtx());
|
|
31
|
+
expect(result.metadata.stages).toEqual(['a', 'b']);
|
|
32
|
+
expect(result.prompt).toBe('after-b');
|
|
33
|
+
});
|
|
34
|
+
it('skips disabled stages', async () => {
|
|
35
|
+
const pipeline = new EnrichmentPipeline();
|
|
36
|
+
pipeline.addStage(makeStage('enabled', 100, { prompt: 'yes' }));
|
|
37
|
+
pipeline.addStage(makeStage('disabled', 200, { prompt: 'no' }, false));
|
|
38
|
+
const result = await pipeline.run(makeCtx());
|
|
39
|
+
expect(result.metadata.stages).toEqual(['enabled']);
|
|
40
|
+
expect(result.prompt).toBe('yes');
|
|
41
|
+
});
|
|
42
|
+
it('merges metadata from multiple stages', async () => {
|
|
43
|
+
const pipeline = new EnrichmentPipeline();
|
|
44
|
+
pipeline.addStage(makeStage('a', 100, { prompt: 'p', metadata: { foo: 1 } }));
|
|
45
|
+
pipeline.addStage(makeStage('b', 200, { prompt: 'p2', metadata: { bar: 2 } }));
|
|
46
|
+
const result = await pipeline.run(makeCtx());
|
|
47
|
+
expect(result.metadata.foo).toBe(1);
|
|
48
|
+
expect(result.metadata.bar).toBe(2);
|
|
49
|
+
expect(result.metadata.stages).toEqual(['a', 'b']);
|
|
50
|
+
});
|
|
51
|
+
it('passes current prompt to next stage', async () => {
|
|
52
|
+
const pipeline = new EnrichmentPipeline();
|
|
53
|
+
const stageA = {
|
|
54
|
+
name: 'a',
|
|
55
|
+
order: 100,
|
|
56
|
+
enabled: () => true,
|
|
57
|
+
enrich: vi.fn(async (_ctx, prompt) => ({ prompt: prompt + '+a' })),
|
|
58
|
+
};
|
|
59
|
+
const stageB = {
|
|
60
|
+
name: 'b',
|
|
61
|
+
order: 200,
|
|
62
|
+
enabled: () => true,
|
|
63
|
+
enrich: vi.fn(async (_ctx, prompt) => ({ prompt: prompt + '+b' })),
|
|
64
|
+
};
|
|
65
|
+
pipeline.addStage(stageB);
|
|
66
|
+
pipeline.addStage(stageA);
|
|
67
|
+
const result = await pipeline.run(makeCtx());
|
|
68
|
+
expect(result.prompt).toBe('base prompt+a+b');
|
|
69
|
+
});
|
|
70
|
+
it('returns base prompt when no stages are enabled', async () => {
|
|
71
|
+
const pipeline = new EnrichmentPipeline();
|
|
72
|
+
pipeline.addStage(makeStage('off', 100, { prompt: 'never' }, false));
|
|
73
|
+
const result = await pipeline.run(makeCtx());
|
|
74
|
+
expect(result.prompt).toBe('base prompt');
|
|
75
|
+
expect(result.metadata.stages).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=pipeline.test.js.map
|
|
@@ -0,0 +1 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;QAC1B,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAE1B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC1C,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAErE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-awareness-stage.test.d.ts","sourceRoot":"","sources":["../../../src/enrichment/__tests__/self-awareness-stage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { SelfAwarenessStage } from '../stages/self-awareness-stage.js';
|
|
3
|
+
function makeCtx(overrides = {}) {
|
|
4
|
+
return {
|
|
5
|
+
basePrompt: 'base',
|
|
6
|
+
userMessage: 'tell me about yourself',
|
|
7
|
+
history: [
|
|
8
|
+
{ role: 'user', content: 'hello' },
|
|
9
|
+
{ role: 'assistant', content: 'hi there' },
|
|
10
|
+
],
|
|
11
|
+
channelType: 'webchat',
|
|
12
|
+
chatId: 'c1',
|
|
13
|
+
sessionId: 's1',
|
|
14
|
+
userId: 'u1',
|
|
15
|
+
toolsUsed: [],
|
|
16
|
+
config: { agent: { personality: 'the-architect' } },
|
|
17
|
+
...overrides,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function makeMockAssembler(returnValue = 'You tend to prefer concise answers.') {
|
|
21
|
+
return {
|
|
22
|
+
assemble: vi.fn().mockResolvedValue(returnValue),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
describe('SelfAwarenessStage', () => {
|
|
26
|
+
it('appends awareness fragment to prompt', async () => {
|
|
27
|
+
const assembler = makeMockAssembler('You tend to prefer concise answers.');
|
|
28
|
+
const stage = new SelfAwarenessStage(assembler);
|
|
29
|
+
const ctx = makeCtx();
|
|
30
|
+
const result = await stage.enrich(ctx, 'current prompt');
|
|
31
|
+
expect(result.prompt).toContain('current prompt');
|
|
32
|
+
expect(result.prompt).toContain('[Dynamic Self-Awareness]');
|
|
33
|
+
expect(result.prompt).toContain('You tend to prefer concise answers.');
|
|
34
|
+
expect(assembler.assemble).toHaveBeenCalledWith({
|
|
35
|
+
userId: 'u1',
|
|
36
|
+
sessionId: 's1',
|
|
37
|
+
chatId: 'c1',
|
|
38
|
+
currentMessage: 'tell me about yourself',
|
|
39
|
+
recentMessages: [
|
|
40
|
+
{ role: 'user', content: 'hello' },
|
|
41
|
+
{ role: 'assistant', content: 'hi there' },
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('returns unchanged prompt when assembler returns null', async () => {
|
|
46
|
+
const assembler = makeMockAssembler(null);
|
|
47
|
+
const stage = new SelfAwarenessStage(assembler);
|
|
48
|
+
const ctx = makeCtx();
|
|
49
|
+
const result = await stage.enrich(ctx, 'current prompt');
|
|
50
|
+
expect(result.prompt).toBe('current prompt');
|
|
51
|
+
});
|
|
52
|
+
it('returns unchanged prompt when assembler returns empty string', async () => {
|
|
53
|
+
const assembler = makeMockAssembler('');
|
|
54
|
+
const stage = new SelfAwarenessStage(assembler);
|
|
55
|
+
const ctx = makeCtx();
|
|
56
|
+
const result = await stage.enrich(ctx, 'current prompt');
|
|
57
|
+
expect(result.prompt).toBe('current prompt');
|
|
58
|
+
});
|
|
59
|
+
it('is always enabled', () => {
|
|
60
|
+
const assembler = makeMockAssembler();
|
|
61
|
+
const stage = new SelfAwarenessStage(assembler);
|
|
62
|
+
const ctx = makeCtx();
|
|
63
|
+
expect(stage.enabled(ctx)).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('has order 400', () => {
|
|
66
|
+
const assembler = makeMockAssembler();
|
|
67
|
+
const stage = new SelfAwarenessStage(assembler);
|
|
68
|
+
expect(stage.order).toBe(400);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=self-awareness-stage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-awareness-stage.test.js","sourceRoot":"","sources":["../../../src/enrichment/__tests__/self-awareness-stage.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAGvE,SAAS,OAAO,CAAC,YAAwC,EAAE;IACzD,OAAO;QACL,UAAU,EAAE,MAAM;QAClB,WAAW,EAAE,wBAAwB;QACrC,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;YAClC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE;SAC3C;QACD,WAAW,EAAE,SAAS;QACtB,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE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AC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.d.ts","sourceRoot":"","sources":["../../../src/enrichment/__tests__/types.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
describe('EnrichmentPipeline types', () => {
|
|
3
|
+
it('EnrichmentContext is structurally valid', () => {
|
|
4
|
+
const ctx = {
|
|
5
|
+
basePrompt: 'base',
|
|
6
|
+
userMessage: 'hello',
|
|
7
|
+
history: [{ role: 'user', content: 'hi' }],
|
|
8
|
+
channelType: 'webchat',
|
|
9
|
+
chatId: 'chat-1',
|
|
10
|
+
sessionId: 'sess-1',
|
|
11
|
+
userId: 'user-1',
|
|
12
|
+
toolsUsed: [{ name: 'web_search', success: true }],
|
|
13
|
+
config: {},
|
|
14
|
+
};
|
|
15
|
+
expect(ctx.channelType).toBe('webchat');
|
|
16
|
+
});
|
|
17
|
+
it('StageResult accepts prompt-only or prompt+metadata', () => {
|
|
18
|
+
const minimal = { prompt: 'p' };
|
|
19
|
+
const full = { prompt: 'p', metadata: { foo: 1 } };
|
|
20
|
+
expect(minimal.prompt).toBe('p');
|
|
21
|
+
expect(full.metadata).toEqual({ foo: 1 });
|
|
22
|
+
});
|
|
23
|
+
it('EnrichmentResult has stages array', () => {
|
|
24
|
+
const result = {
|
|
25
|
+
prompt: 'enriched',
|
|
26
|
+
metadata: { stages: ['memory', 'mode'] },
|
|
27
|
+
};
|
|
28
|
+
expect(result.metadata.stages).toHaveLength(2);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=types.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../../src/enrichment/__tests__/types.test.ts"],"names":[],"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,MAAM,CAAC,EAAE;SACzC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { EnrichmentContext, EnrichmentStage, StageResult, EnrichmentResult, ArchitectMeta } from './types.js';
|
|
2
|
+
export { EnrichmentPipeline } from './pipeline.js';
|
|
3
|
+
export { MemoryStage } from './stages/memory-stage.js';
|
|
4
|
+
export { ModeStage } from './stages/mode-stage.js';
|
|
5
|
+
export { ArchitectStage } from './stages/architect-stage.js';
|
|
6
|
+
export { SelfAwarenessStage } from './stages/self-awareness-stage.js';
|
|
7
|
+
export { ModelIdentityStage } from './stages/model-identity-stage.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enrichment/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { EnrichmentPipeline } from './pipeline.js';
|
|
2
|
+
export { MemoryStage } from './stages/memory-stage.js';
|
|
3
|
+
export { ModeStage } from './stages/mode-stage.js';
|
|
4
|
+
export { ArchitectStage } from './stages/architect-stage.js';
|
|
5
|
+
export { SelfAwarenessStage } from './stages/self-awareness-stage.js';
|
|
6
|
+
export { ModelIdentityStage } from './stages/model-identity-stage.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enrichment/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EnrichmentContext, EnrichmentResult, EnrichmentStage } from './types.js';
|
|
2
|
+
export declare class EnrichmentPipeline {
|
|
3
|
+
private stages;
|
|
4
|
+
addStage(stage: EnrichmentStage): void;
|
|
5
|
+
run(ctx: EnrichmentContext): Promise<EnrichmentResult>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/enrichment/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvF,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAyB;IAEvC,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAKhC,GAAG,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAsB7D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class EnrichmentPipeline {
|
|
2
|
+
stages = [];
|
|
3
|
+
addStage(stage) {
|
|
4
|
+
this.stages.push(stage);
|
|
5
|
+
this.stages.sort((a, b) => a.order - b.order);
|
|
6
|
+
}
|
|
7
|
+
async run(ctx) {
|
|
8
|
+
let prompt = ctx.basePrompt;
|
|
9
|
+
const allMetadata = {};
|
|
10
|
+
const stagesRun = [];
|
|
11
|
+
for (const stage of this.stages) {
|
|
12
|
+
if (!stage.enabled(ctx))
|
|
13
|
+
continue;
|
|
14
|
+
const result = await stage.enrich(ctx, prompt);
|
|
15
|
+
prompt = result.prompt;
|
|
16
|
+
if (result.metadata) {
|
|
17
|
+
for (const [k, v] of Object.entries(result.metadata)) {
|
|
18
|
+
allMetadata[k] = v;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
stagesRun.push(stage.name);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
prompt,
|
|
25
|
+
metadata: { ...allMetadata, stages: stagesRun },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/enrichment/pipeline.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IACrB,MAAM,GAAsB,EAAE,CAAC;IAEvC,QAAQ,CAAC,KAAsB;QAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAsB;QAC9B,IAAI,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC;QAC5B,MAAM,WAAW,GAA4B,EAAE,CAAC;QAChD,MAAM,SAAS,GAAa,EAAE,CAAC;QAE/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;gBAAE,SAAS;YAClC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC/C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACvB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACrD,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC;YACD,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO;YACL,MAAM;YACN,QAAQ,EAAE,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE;SAChD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { EnrichmentContext, EnrichmentStage, StageResult } from '../types.js';
|
|
2
|
+
/** Structural type for TheArchitect — avoids import coupling.
|
|
3
|
+
* Uses `object` where the real API has branded interfaces (e.g. TaskContext)
|
|
4
|
+
* so that structural assignability works without an index signature. */
|
|
5
|
+
interface ArchitectLike {
|
|
6
|
+
generatePrompt(userMessage: string, history?: ReadonlyArray<{
|
|
7
|
+
role: string;
|
|
8
|
+
content: string;
|
|
9
|
+
}>): {
|
|
10
|
+
contextModifier: string;
|
|
11
|
+
detectedContext: object;
|
|
12
|
+
activeTraits: ReadonlyArray<object>;
|
|
13
|
+
emotionalTrajectory?: string;
|
|
14
|
+
escalationAlert?: boolean;
|
|
15
|
+
recommendation?: object;
|
|
16
|
+
relevantDecisions?: ReadonlyArray<{
|
|
17
|
+
summary: string;
|
|
18
|
+
status: string;
|
|
19
|
+
}>;
|
|
20
|
+
feedbackInsight?: {
|
|
21
|
+
weakDomains: string[];
|
|
22
|
+
trend: string;
|
|
23
|
+
suggestedAdjustments: Record<string, number>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
getTraitMix(context: object): object;
|
|
27
|
+
}
|
|
28
|
+
/** Structural type for ArchitectBridge. */
|
|
29
|
+
interface BridgeLike {
|
|
30
|
+
afterPrompt(detectedContext: Record<string, unknown>, emotionalTrajectory: string | undefined, escalationAlert: boolean | undefined, chatId: string): void;
|
|
31
|
+
}
|
|
32
|
+
/** Structural type for ArchitectAwarenessCollector. */
|
|
33
|
+
interface CollectorLike {
|
|
34
|
+
updateToolContext(tools: ReadonlyArray<{
|
|
35
|
+
name: string;
|
|
36
|
+
success: boolean;
|
|
37
|
+
}>): void;
|
|
38
|
+
}
|
|
39
|
+
export declare class ArchitectStage implements EnrichmentStage {
|
|
40
|
+
private readonly architect;
|
|
41
|
+
private readonly bridge?;
|
|
42
|
+
private readonly awarenessCollector?;
|
|
43
|
+
private readonly selfModelGetter?;
|
|
44
|
+
private readonly userModelGetter?;
|
|
45
|
+
readonly name = "architect";
|
|
46
|
+
readonly order = 300;
|
|
47
|
+
constructor(architect: ArchitectLike, bridge?: BridgeLike | undefined, awarenessCollector?: CollectorLike | undefined, selfModelGetter?: (() => Promise<{
|
|
48
|
+
selfNarrative?: string;
|
|
49
|
+
} | null>) | undefined, userModelGetter?: (() => {
|
|
50
|
+
narrative?: string;
|
|
51
|
+
} | null) | undefined);
|
|
52
|
+
enabled(ctx: EnrichmentContext): boolean;
|
|
53
|
+
enrich(ctx: EnrichmentContext, currentPrompt: string): Promise<StageResult>;
|
|
54
|
+
private buildConsciousnessSection;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=architect-stage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"architect-stage.d.ts","sourceRoot":"","sources":["../../../src/enrichment/stages/architect-stage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnF;;yEAEyE;AACzE,UAAU,aAAa;IACrB,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GACzD;QACD,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QACpC,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,iBAAiB,CAAC,EAAE,aAAa,CAAC;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACvE,eAAe,CAAC,EAAE;YAChB,WAAW,EAAE,MAAM,EAAE,CAAC;YACtB,KAAK,EAAE,MAAM,CAAC;YACd,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAC9C,CAAC;KACH,CAAC;IACF,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CACtC;AAED,2CAA2C;AAC3C,UAAU,UAAU;IAClB,WAAW,CACT,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EACvC,eAAe,EAAE,OAAO,GAAG,SAAS,EACpC,MAAM,EAAE,MAAM,GACb,IAAI,CAAC;CACT;AAED,uDAAuD;AACvD,UAAU,aAAa;IACrB,iBAAiB,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CACnF;AAED,qBAAa,cAAe,YAAW,eAAe;IAKlD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IARnC,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,KAAK,OAAO;gBAGF,SAAS,EAAE,aAAa,EACxB,MAAM,CAAC,EAAE,UAAU,YAAA,EACnB,kBAAkB,CAAC,EAAE,aAAa,YAAA,EAClC,eAAe,CAAC,GAAE,MAAM,OAAO,CAAC;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,aAAA,EAClE,eAAe,CAAC,GAAE,MAAM;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,aAAA;IAGxE,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO;IAIlC,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YA2DnE,yBAAyB;CAsDxC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export class ArchitectStage {
|
|
2
|
+
architect;
|
|
3
|
+
bridge;
|
|
4
|
+
awarenessCollector;
|
|
5
|
+
selfModelGetter;
|
|
6
|
+
userModelGetter;
|
|
7
|
+
name = 'architect';
|
|
8
|
+
order = 300;
|
|
9
|
+
constructor(architect, bridge, awarenessCollector, selfModelGetter, userModelGetter) {
|
|
10
|
+
this.architect = architect;
|
|
11
|
+
this.bridge = bridge;
|
|
12
|
+
this.awarenessCollector = awarenessCollector;
|
|
13
|
+
this.selfModelGetter = selfModelGetter;
|
|
14
|
+
this.userModelGetter = userModelGetter;
|
|
15
|
+
}
|
|
16
|
+
enabled(ctx) {
|
|
17
|
+
return ctx.config.agent?.personality === 'the-architect';
|
|
18
|
+
}
|
|
19
|
+
async enrich(ctx, currentPrompt) {
|
|
20
|
+
// GAP 1: Pass conversation history to generatePrompt
|
|
21
|
+
const output = this.architect.generatePrompt(ctx.userMessage, ctx.history);
|
|
22
|
+
// GAP 2: Feed tool usage to awareness collector
|
|
23
|
+
if (this.awarenessCollector && ctx.toolsUsed.length > 0) {
|
|
24
|
+
this.awarenessCollector.updateToolContext(ctx.toolsUsed);
|
|
25
|
+
}
|
|
26
|
+
// Bridge side effects: persistence, awareness feeding, escalation logging
|
|
27
|
+
if (this.bridge && ctx.chatId) {
|
|
28
|
+
this.bridge.afterPrompt({ ...output.detectedContext }, output.emotionalTrajectory, output.escalationAlert, ctx.chatId);
|
|
29
|
+
}
|
|
30
|
+
// GAP 3: Channel hint for non-webchat channels
|
|
31
|
+
let channelHint = '';
|
|
32
|
+
if (ctx.channelType && ctx.channelType !== 'webchat') {
|
|
33
|
+
channelHint = `\n[Channel: ${ctx.channelType}]`;
|
|
34
|
+
}
|
|
35
|
+
// Build trait weights map
|
|
36
|
+
const mix = this.architect.getTraitMix(output.detectedContext);
|
|
37
|
+
const traitWeights = {};
|
|
38
|
+
for (const [key, val] of Object.entries(mix)) {
|
|
39
|
+
traitWeights[key] = val;
|
|
40
|
+
}
|
|
41
|
+
// Build consciousness section
|
|
42
|
+
const consciousnessSection = await this.buildConsciousnessSection(output);
|
|
43
|
+
// Assemble final prompt
|
|
44
|
+
const prompt = currentPrompt +
|
|
45
|
+
'\n\n' +
|
|
46
|
+
output.contextModifier +
|
|
47
|
+
channelHint +
|
|
48
|
+
consciousnessSection;
|
|
49
|
+
// GAP 4: Return full architect metadata including channelType
|
|
50
|
+
return {
|
|
51
|
+
prompt,
|
|
52
|
+
metadata: {
|
|
53
|
+
architect: {
|
|
54
|
+
detectedContext: output.detectedContext,
|
|
55
|
+
activeTraits: output.activeTraits,
|
|
56
|
+
traitWeights,
|
|
57
|
+
recommendation: output.recommendation,
|
|
58
|
+
escalationAlert: output.escalationAlert,
|
|
59
|
+
channelType: ctx.channelType,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async buildConsciousnessSection(output) {
|
|
65
|
+
const parts = [];
|
|
66
|
+
// Active decisions (top 5)
|
|
67
|
+
if (output.relevantDecisions && output.relevantDecisions.length > 0) {
|
|
68
|
+
const items = output.relevantDecisions
|
|
69
|
+
.slice(0, 5)
|
|
70
|
+
.map((d) => `- ${d.summary} [${d.status}]`)
|
|
71
|
+
.join('\n');
|
|
72
|
+
parts.push(`**Active Decisions:**\n${items}`);
|
|
73
|
+
}
|
|
74
|
+
// Self-improvement notes from feedback
|
|
75
|
+
if (output.feedbackInsight) {
|
|
76
|
+
const fi = output.feedbackInsight;
|
|
77
|
+
const notes = [];
|
|
78
|
+
if (fi.weakDomains.length > 0) {
|
|
79
|
+
notes.push(`Weak domains: ${fi.weakDomains.join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
if (fi.trend !== 'stable') {
|
|
82
|
+
notes.push(`Satisfaction trend: ${fi.trend}`);
|
|
83
|
+
}
|
|
84
|
+
const adjustments = Object.entries(fi.suggestedAdjustments);
|
|
85
|
+
if (adjustments.length > 0) {
|
|
86
|
+
notes.push(`Suggested adjustments: ${adjustments.map(([k, v]) => `${k} ${v > 0 ? '+' : ''}${v}`).join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
if (notes.length > 0) {
|
|
89
|
+
parts.push(`**Self-Improvement Notes:**\n${notes.map((n) => `- ${n}`).join('\n')}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Self-model narrative
|
|
93
|
+
if (this.selfModelGetter) {
|
|
94
|
+
const selfModel = await this.selfModelGetter();
|
|
95
|
+
if (selfModel?.selfNarrative) {
|
|
96
|
+
parts.push(`**Self-Model:**\n${selfModel.selfNarrative}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// User model narrative
|
|
100
|
+
if (this.userModelGetter) {
|
|
101
|
+
const userModel = this.userModelGetter();
|
|
102
|
+
if (userModel?.narrative) {
|
|
103
|
+
parts.push(`**User Model:**\n${userModel.narrative}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (parts.length > 0) {
|
|
107
|
+
return '\n\n[Consciousness]\n' + parts.join('\n\n');
|
|
108
|
+
}
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=architect-stage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"architect-stage.js","sourceRoot":"","sources":["../../../src/enrichment/stages/architect-stage.ts"],"names":[],"mappings":"AAyCA,MAAM,OAAO,cAAc;IAKN;IACA;IACA;IACA;IACA;IARV,IAAI,GAAG,WAAW,CAAC;IACnB,KAAK,GAAG,GAAG,CAAC;IAErB,YACmB,SAAwB,EACxB,MAAmB,EACnB,kBAAkC,EAClC,eAAkE,EAClE,eAAqD;QAJrD,cAAS,GAAT,SAAS,CAAe;QACxB,WAAM,GAAN,MAAM,CAAa;QACnB,uBAAkB,GAAlB,kBAAkB,CAAgB;QAClC,oBAAe,GAAf,eAAe,CAAmD;QAClE,oBAAe,GAAf,eAAe,CAAsC;IACrE,CAAC;IAEJ,OAAO,CAAC,GAAsB;QAC5B,OAAQ,GAAG,CAAC,MAAc,CAAC,KAAK,EAAE,WAAW,KAAK,eAAe,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAsB,EAAE,aAAqB;QACxD,qDAAqD;QACrD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3E,gDAAgD;QAChD,IAAI,IAAI,CAAC,kBAAkB,IAAI,GAAG,CAAC,SA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AC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EnrichmentContext, EnrichmentStage, StageResult } from '../types.js';
|
|
2
|
+
export declare class MemoryStage implements EnrichmentStage {
|
|
3
|
+
private readonly store;
|
|
4
|
+
private readonly retriever;
|
|
5
|
+
readonly name = "memory";
|
|
6
|
+
readonly order = 100;
|
|
7
|
+
constructor(store: {
|
|
8
|
+
getAll(): Promise<unknown[]>;
|
|
9
|
+
}, retriever: {
|
|
10
|
+
retrieve(memories: unknown[], userMessage: string): string | null;
|
|
11
|
+
});
|
|
12
|
+
enabled(_ctx: EnrichmentContext): boolean;
|
|
13
|
+
enrich(ctx: EnrichmentContext, currentPrompt: string): Promise<StageResult>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=memory-stage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-stage.d.ts","sourceRoot":"","sources":["../../../src/enrichment/stages/memory-stage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnF,qBAAa,WAAY,YAAW,eAAe;IAK/C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL5B,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,KAAK,OAAO;gBAGF,KAAK,EAAE;QAAE,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EACvC,SAAS,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE;IAGnG,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO;IAInC,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAKlF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class MemoryStage {
|
|
2
|
+
store;
|
|
3
|
+
retriever;
|
|
4
|
+
name = 'memory';
|
|
5
|
+
order = 100;
|
|
6
|
+
constructor(store, retriever) {
|
|
7
|
+
this.store = store;
|
|
8
|
+
this.retriever = retriever;
|
|
9
|
+
}
|
|
10
|
+
enabled(_ctx) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
async enrich(ctx, currentPrompt) {
|
|
14
|
+
const memories = await this.store.getAll();
|
|
15
|
+
const section = this.retriever.retrieve(memories, ctx.userMessage);
|
|
16
|
+
return { prompt: section ? currentPrompt + section : currentPrompt };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=memory-stage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-stage.js","sourceRoot":"","sources":["../../../src/enrichment/stages/memory-stage.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IAKH;IACA;IALV,IAAI,GAAG,QAAQ,CAAC;IAChB,KAAK,GAAG,GAAG,CAAC;IAErB,YACmB,KAAuC,EACvC,SAAgF;QADhF,UAAK,GAAL,KAAK,CAAkC;QACvC,cAAS,GAAT,SAAS,CAAuE;IAChG,CAAC;IAEJ,OAAO,CAAC,IAAuB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAsB,EAAE,aAAqB;QACxD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;QACnE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { EnrichmentContext, EnrichmentStage, StageResult } from '../types.js';
|
|
2
|
+
interface ModeDetectorLike {
|
|
3
|
+
detect(content: string, opts?: {
|
|
4
|
+
taskType?: string;
|
|
5
|
+
currentState?: unknown;
|
|
6
|
+
}): {
|
|
7
|
+
mode: string;
|
|
8
|
+
} | null;
|
|
9
|
+
}
|
|
10
|
+
interface PromptAssemblerLike {
|
|
11
|
+
enrichForMessage(modeState: unknown, memorySection: string | null, prefs: unknown, extra: unknown, channelType?: string): string;
|
|
12
|
+
enrichForSecurityContext(secCtx: unknown, floor: unknown, memorySection: string | null): string;
|
|
13
|
+
}
|
|
14
|
+
interface SecurityFloorLike {
|
|
15
|
+
detectSecurityContext(opts: {
|
|
16
|
+
userMessage: string;
|
|
17
|
+
}): {
|
|
18
|
+
active: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface SessionModeStateLike {
|
|
22
|
+
activeMode: string;
|
|
23
|
+
autoDetected: boolean;
|
|
24
|
+
lastAutoMode?: string;
|
|
25
|
+
lastSwitchAt?: number;
|
|
26
|
+
suspendedMode?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ModeStageOptions {
|
|
29
|
+
readonly getModeState: (sessionId: string) => SessionModeStateLike;
|
|
30
|
+
readonly detector: ModeDetectorLike;
|
|
31
|
+
readonly assembler: PromptAssemblerLike;
|
|
32
|
+
readonly securityFloor?: SecurityFloorLike;
|
|
33
|
+
readonly userPreferences?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export declare class ModeStage implements EnrichmentStage {
|
|
36
|
+
readonly name = "mode";
|
|
37
|
+
readonly order = 200;
|
|
38
|
+
private readonly getModeState;
|
|
39
|
+
private readonly detector;
|
|
40
|
+
private readonly assembler;
|
|
41
|
+
private readonly securityFloor?;
|
|
42
|
+
private readonly userPreferences?;
|
|
43
|
+
constructor(opts: ModeStageOptions);
|
|
44
|
+
enabled(ctx: EnrichmentContext): boolean;
|
|
45
|
+
enrich(ctx: EnrichmentContext, currentPrompt: string): Promise<StageResult>;
|
|
46
|
+
private buildModeEnrichedPrompt;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=mode-stage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode-stage.d.ts","sourceRoot":"","sources":["../../../src/enrichment/stages/mode-stage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnF,UAAU,gBAAgB;IACxB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACxG;AAED,UAAU,mBAAmB;IAC3B,gBAAgB,CACd,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,OAAO,EACd,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAAC;IACV,wBAAwB,CACtB,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,EACd,aAAa,EAAE,MAAM,GAAG,IAAI,GAC3B,MAAM,CAAC;CACX;AAED,UAAU,iBAAiB;IACzB,qBAAqB,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3E;AAED,UAAU,oBAAoB;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,oBAAoB,CAAC;IACnE,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,qBAAa,SAAU,YAAW,eAAe;IAC/C,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,KAAK,OAAO;IAErB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8C;IAC3E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAU;gBAE/B,IAAI,EAAE,gBAAgB;IAQlC,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO;IAIlC,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAoCjF,OAAO,CAAC,uBAAuB;CAoChC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export class ModeStage {
|
|
2
|
+
name = 'mode';
|
|
3
|
+
order = 200;
|
|
4
|
+
getModeState;
|
|
5
|
+
detector;
|
|
6
|
+
assembler;
|
|
7
|
+
securityFloor;
|
|
8
|
+
userPreferences;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.getModeState = opts.getModeState;
|
|
11
|
+
this.detector = opts.detector;
|
|
12
|
+
this.assembler = opts.assembler;
|
|
13
|
+
this.securityFloor = opts.securityFloor;
|
|
14
|
+
this.userPreferences = opts.userPreferences;
|
|
15
|
+
}
|
|
16
|
+
enabled(ctx) {
|
|
17
|
+
return ctx.config.modes?.enabled !== false;
|
|
18
|
+
}
|
|
19
|
+
async enrich(ctx, currentPrompt) {
|
|
20
|
+
const modeState = this.getModeState(ctx.sessionId);
|
|
21
|
+
if (this.securityFloor) {
|
|
22
|
+
const securityContext = this.securityFloor.detectSecurityContext({
|
|
23
|
+
userMessage: ctx.userMessage,
|
|
24
|
+
});
|
|
25
|
+
if (securityContext.active) {
|
|
26
|
+
modeState.suspendedMode = modeState.activeMode;
|
|
27
|
+
const prompt = this.assembler.enrichForSecurityContext(securityContext, this.securityFloor, null);
|
|
28
|
+
return { prompt, metadata: { securityFloorActive: true } };
|
|
29
|
+
}
|
|
30
|
+
if (modeState.suspendedMode) {
|
|
31
|
+
modeState.activeMode = modeState.suspendedMode;
|
|
32
|
+
delete modeState.suspendedMode;
|
|
33
|
+
const prompt = this.assembler.enrichForMessage(modeState, null, this.userPreferences, undefined, ctx.channelType);
|
|
34
|
+
return { prompt, metadata: { modeRestored: true } };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Normal mode detection
|
|
38
|
+
return { prompt: this.buildModeEnrichedPrompt(ctx, modeState) };
|
|
39
|
+
}
|
|
40
|
+
buildModeEnrichedPrompt(ctx, modeState) {
|
|
41
|
+
if (modeState.activeMode === 'auto' &&
|
|
42
|
+
ctx.config.modes?.autoDetection !== false) {
|
|
43
|
+
const detection = this.detector.detect(ctx.userMessage, {
|
|
44
|
+
currentState: modeState,
|
|
45
|
+
});
|
|
46
|
+
if (detection) {
|
|
47
|
+
modeState.lastAutoMode = detection.mode;
|
|
48
|
+
modeState.autoDetected = true;
|
|
49
|
+
modeState.lastSwitchAt = Date.now();
|
|
50
|
+
const tempState = {
|
|
51
|
+
...modeState,
|
|
52
|
+
activeMode: detection.mode,
|
|
53
|
+
};
|
|
54
|
+
return this.assembler.enrichForMessage(tempState, null, this.userPreferences, undefined, ctx.channelType);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return this.assembler.enrichForMessage(modeState, null, this.userPreferences, undefined, ctx.channelType);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=mode-stage.js.map
|