@dxos/assistant 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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/lib/neutral/extraction/index.mjs +4 -21
- package/dist/lib/neutral/extraction/index.mjs.map +3 -3
- package/dist/lib/neutral/index.mjs +1259 -79
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/conversation/context.d.ts +9 -12
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/index.d.ts +1 -1
- package/dist/types/src/conversation/index.d.ts.map +1 -1
- package/dist/types/src/conversation/session.d.ts +78 -0
- package/dist/types/src/conversation/session.d.ts.map +1 -0
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +12 -12
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +461 -455
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +7 -29
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/error-handling.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +6 -3
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -1
- package/dist/types/src/session/{session.d.ts → request.d.ts} +25 -33
- package/dist/types/src/session/request.d.ts.map +1 -0
- package/dist/types/src/session/toolkit.d.ts +5 -7
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/templates/system.d.ts +1 -1
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/tracing.d.ts +64 -95
- package/dist/types/src/tracing.d.ts.map +1 -1
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -38
- package/src/conversation/context.ts +1 -1
- package/src/conversation/index.ts +1 -1
- package/src/conversation/session.ts +334 -0
- package/src/execution-graph.ts +15 -5
- package/src/extraction/extraction.ts +1 -1
- package/src/functions/services.ts +12 -127
- package/src/functions.conversations.json +1 -1
- package/src/index.ts +0 -1
- package/src/session/format.ts +14 -9
- package/src/session/index.ts +1 -1
- package/src/session/request.conversations.json +1 -0
- package/src/session/{session.ts → request.ts} +44 -51
- package/src/session/toolkit.ts +18 -15
- package/src/templates/instructions/system.tpl +11 -0
- package/src/templates/system.ts +1 -1
- package/src/tracing.ts +13 -69
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs +0 -1875
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs.map +0 -7
- package/dist/lib/neutral/testing/index.mjs +0 -114
- package/dist/lib/neutral/testing/index.mjs.map +0 -7
- package/dist/types/src/conversation/conversation.d.ts +0 -68
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.test.d.ts +0 -2
- package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
- package/dist/types/src/functions.test.d.ts +0 -2
- package/dist/types/src/functions.test.d.ts.map +0 -1
- package/dist/types/src/service/AgentService.d.ts +0 -61
- package/dist/types/src/service/AgentService.d.ts.map +0 -1
- package/dist/types/src/service/AgentService.test.d.ts +0 -2
- package/dist/types/src/service/AgentService.test.d.ts.map +0 -1
- package/dist/types/src/service/agent-process.d.ts +0 -17
- package/dist/types/src/service/agent-process.d.ts.map +0 -1
- package/dist/types/src/service/index.d.ts +0 -3
- package/dist/types/src/service/index.d.ts.map +0 -1
- package/dist/types/src/session/format.test.d.ts +0 -2
- package/dist/types/src/session/format.test.d.ts.map +0 -1
- package/dist/types/src/session/session.d.ts.map +0 -1
- package/dist/types/src/session/session.test.d.ts +0 -2
- package/dist/types/src/session/session.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -35
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/src/conversation/conversation.test.ts +0 -58
- package/src/conversation/conversation.ts +0 -275
- package/src/functions.test.ts +0 -82
- package/src/service/AgentService.conversations.json +0 -1
- package/src/service/AgentService.test.ts +0 -169
- package/src/service/AgentService.ts +0 -165
- package/src/service/agent-process.ts +0 -359
- package/src/service/index.ts +0 -6
- package/src/session/format.test.ts +0 -132
- package/src/session/session.conversations.json +0 -1
- package/src/session/session.test.ts +0 -190
- package/src/testing/index.ts +0 -5
- package/src/testing/layer.ts +0 -259
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Tool from '@effect/ai/Tool';
|
|
6
|
-
import * as Toolkit from '@effect/ai/Toolkit';
|
|
7
|
-
import { describe, expect, it } from '@effect/vitest';
|
|
8
|
-
import * as Effect from 'effect/Effect';
|
|
9
|
-
import * as Layer from 'effect/Layer';
|
|
10
|
-
import * as Schema from 'effect/Schema';
|
|
11
|
-
|
|
12
|
-
import { Obj, Type } from '@dxos/echo';
|
|
13
|
-
import { TestHelpers } from '@dxos/effect/testing';
|
|
14
|
-
import { log } from '@dxos/log';
|
|
15
|
-
import { Message } from '@dxos/types';
|
|
16
|
-
|
|
17
|
-
import { AssistantTestLayer } from '../testing';
|
|
18
|
-
import { AiSession } from './session';
|
|
19
|
-
|
|
20
|
-
// Define a calendar event artifact schema.
|
|
21
|
-
const CalendarEventSchema = Schema.Struct({
|
|
22
|
-
title: Schema.String,
|
|
23
|
-
startTime: Schema.String,
|
|
24
|
-
endTime: Schema.String,
|
|
25
|
-
description: Schema.String,
|
|
26
|
-
}).pipe(
|
|
27
|
-
Type.object({
|
|
28
|
-
typename: 'com.example.type.calendar-event',
|
|
29
|
-
version: '0.1.0',
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
34
|
-
|
|
35
|
-
const TestToolkit = Toolkit.make(
|
|
36
|
-
Tool.make('Calculator', {
|
|
37
|
-
description: 'Basic calculator tool',
|
|
38
|
-
parameters: {
|
|
39
|
-
input: Schema.String.annotations({
|
|
40
|
-
description: 'The calculation to perform.',
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
success: Schema.Struct({
|
|
44
|
-
result: Schema.Number,
|
|
45
|
-
}),
|
|
46
|
-
failure: Schema.Never,
|
|
47
|
-
}),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Tool handlers.
|
|
51
|
-
const toolkitLayer = TestToolkit.toLayer({
|
|
52
|
-
Calculator: ({ input }) =>
|
|
53
|
-
Effect.gen(function* () {
|
|
54
|
-
const result = (() => {
|
|
55
|
-
// Restrict to basic arithmetic operations for safety.
|
|
56
|
-
const sanitizedInput = input.replace(/[^0-9+\-*/().\s]/g, '');
|
|
57
|
-
log.info('calculate', { sanitizedInput });
|
|
58
|
-
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
60
|
-
return Function(`"use strict"; return (${sanitizedInput})`)();
|
|
61
|
-
})();
|
|
62
|
-
|
|
63
|
-
return { result };
|
|
64
|
-
}),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const TestLayer = Layer.mergeAll(
|
|
68
|
-
AssistantTestLayer({
|
|
69
|
-
types: [CalendarEventSchema],
|
|
70
|
-
tracing: 'pretty',
|
|
71
|
-
}),
|
|
72
|
-
toolkitLayer,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
describe('AiSession', () => {
|
|
76
|
-
it.effect(
|
|
77
|
-
'no tools',
|
|
78
|
-
Effect.fnUntraced(
|
|
79
|
-
function* (_) {
|
|
80
|
-
const session = new AiSession();
|
|
81
|
-
const response = yield* session.run({
|
|
82
|
-
prompt: 'Hello world!',
|
|
83
|
-
history: [],
|
|
84
|
-
});
|
|
85
|
-
log.info('response', { response });
|
|
86
|
-
},
|
|
87
|
-
Effect.provide(TestLayer),
|
|
88
|
-
TestHelpers.provideTestContext,
|
|
89
|
-
),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
it.effect(
|
|
93
|
-
'calculator',
|
|
94
|
-
Effect.fnUntraced(
|
|
95
|
-
function* (_) {
|
|
96
|
-
const session = new AiSession();
|
|
97
|
-
const toolkit = yield* TestToolkit;
|
|
98
|
-
const response = yield* session.run({
|
|
99
|
-
toolkit,
|
|
100
|
-
prompt: 'What is 10 + 30?',
|
|
101
|
-
history: [],
|
|
102
|
-
});
|
|
103
|
-
log.info('response', { response });
|
|
104
|
-
},
|
|
105
|
-
Effect.provide(TestLayer),
|
|
106
|
-
TestHelpers.provideTestContext,
|
|
107
|
-
),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
it.effect(
|
|
111
|
-
'tool schema error',
|
|
112
|
-
Effect.fnUntraced(
|
|
113
|
-
function* (_) {
|
|
114
|
-
const session = new AiSession();
|
|
115
|
-
const toolkit = yield* TestToolkit;
|
|
116
|
-
const response = yield* session.run({
|
|
117
|
-
toolkit,
|
|
118
|
-
prompt:
|
|
119
|
-
'I am testing error handling in tool paramter parsing. I want you to call the calculator tool but omit the input parameter to intentionally differ from the tool schema.',
|
|
120
|
-
history: [],
|
|
121
|
-
});
|
|
122
|
-
log.info('response', { response });
|
|
123
|
-
},
|
|
124
|
-
Effect.provide(TestLayer),
|
|
125
|
-
TestHelpers.provideTestContext,
|
|
126
|
-
),
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
it.effect(
|
|
130
|
-
'summarization',
|
|
131
|
-
Effect.fnUntraced(
|
|
132
|
-
function* (_) {
|
|
133
|
-
const session = new AiSession({ summarizationThreshold: 0 }); // Force summarization.
|
|
134
|
-
const response = yield* session.run({
|
|
135
|
-
prompt: 'What did we talk about?',
|
|
136
|
-
history: [
|
|
137
|
-
Obj.make(Message.Message, {
|
|
138
|
-
created: '2024-01-01T10:00:00Z',
|
|
139
|
-
sender: { role: 'user' },
|
|
140
|
-
blocks: [{ _tag: 'text', text: 'How many apples are in the basket?' }],
|
|
141
|
-
}),
|
|
142
|
-
Obj.make(Message.Message, {
|
|
143
|
-
created: '2024-01-01T11:00:00Z',
|
|
144
|
-
sender: { role: 'assistant' },
|
|
145
|
-
blocks: [{ _tag: 'text', text: 'There are 10 apples in the basket.' }],
|
|
146
|
-
}),
|
|
147
|
-
],
|
|
148
|
-
});
|
|
149
|
-
expect(response).toBeDefined();
|
|
150
|
-
},
|
|
151
|
-
Effect.provide(TestLayer),
|
|
152
|
-
TestHelpers.provideTestContext,
|
|
153
|
-
),
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Travel to rome, florence, livorno, siena, madrid for conferences
|
|
158
|
-
|
|
159
|
-
const _CALENDAR_EVENTS: CalendarEvent[] = [
|
|
160
|
-
Obj.make(CalendarEventSchema, {
|
|
161
|
-
title: 'Exploring Ancient Ruins in Rome',
|
|
162
|
-
startTime: '2024-01-01T10:00:00Z',
|
|
163
|
-
endTime: '2024-01-01T11:00:00Z',
|
|
164
|
-
description: 'Tech conference at the historic Colosseum with networking opportunities',
|
|
165
|
-
}),
|
|
166
|
-
Obj.make(CalendarEventSchema, {
|
|
167
|
-
title: 'Renaissance Tech Summit in Florence',
|
|
168
|
-
startTime: '2024-01-01T11:00:00Z',
|
|
169
|
-
endTime: '2024-01-01T12:00:00Z',
|
|
170
|
-
description: 'Discussing AI innovations surrounded by Renaissance art',
|
|
171
|
-
}),
|
|
172
|
-
Obj.make(CalendarEventSchema, {
|
|
173
|
-
title: 'Travel to Livorno',
|
|
174
|
-
startTime: '2024-01-01T12:00:00Z',
|
|
175
|
-
endTime: '2024-01-01T13:00:00Z',
|
|
176
|
-
description: 'Travel to Livorno',
|
|
177
|
-
}),
|
|
178
|
-
Obj.make(CalendarEventSchema, {
|
|
179
|
-
title: 'Travel to Siena',
|
|
180
|
-
startTime: '2024-01-01T13:00:00Z',
|
|
181
|
-
endTime: '2024-01-01T14:00:00Z',
|
|
182
|
-
description: 'Travel to Siena',
|
|
183
|
-
}),
|
|
184
|
-
Obj.make(CalendarEventSchema, {
|
|
185
|
-
title: 'Travel to Madrid',
|
|
186
|
-
startTime: '2024-01-01T14:00:00Z',
|
|
187
|
-
endTime: '2024-01-01T15:00:00Z',
|
|
188
|
-
description: 'Travel to Madrid',
|
|
189
|
-
}),
|
|
190
|
-
];
|
package/src/testing/index.ts
DELETED
package/src/testing/layer.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2026 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Registry } from '@effect-atom/atom';
|
|
6
|
-
import * as LanguageModel from '@effect/ai/LanguageModel';
|
|
7
|
-
import * as KeyValueStore from '@effect/platform/KeyValueStore';
|
|
8
|
-
import * as Array from 'effect/Array';
|
|
9
|
-
import * as Context from 'effect/Context';
|
|
10
|
-
import * as Effect from 'effect/Effect';
|
|
11
|
-
import * as Layer from 'effect/Layer';
|
|
12
|
-
import * as Match from 'effect/Match';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
AiService,
|
|
16
|
-
ConsolePrinter,
|
|
17
|
-
GenericToolkit,
|
|
18
|
-
type ModelName,
|
|
19
|
-
type ToolExecutionService,
|
|
20
|
-
type ToolResolverService,
|
|
21
|
-
} from '@dxos/ai';
|
|
22
|
-
import { TestAiService } from '@dxos/ai/testing';
|
|
23
|
-
import { Blueprint, Prompt } from '@dxos/blueprints';
|
|
24
|
-
import { Database, DXN, Feed, Type } from '@dxos/echo';
|
|
25
|
-
import { acquireReleaseResource } from '@dxos/effect';
|
|
26
|
-
import type { TestContextService } from '@dxos/effect/testing';
|
|
27
|
-
import {
|
|
28
|
-
CredentialsService,
|
|
29
|
-
FunctionInvocationService,
|
|
30
|
-
QueueService,
|
|
31
|
-
type ServiceCredential,
|
|
32
|
-
ServiceNotAvailableError,
|
|
33
|
-
Trace,
|
|
34
|
-
TracingService,
|
|
35
|
-
} from '@dxos/functions';
|
|
36
|
-
import {
|
|
37
|
-
Process,
|
|
38
|
-
ProcessManager,
|
|
39
|
-
ServiceResolver,
|
|
40
|
-
TracingServiceExt,
|
|
41
|
-
TriggerDispatcher,
|
|
42
|
-
TriggerStateStore,
|
|
43
|
-
} from '@dxos/functions-runtime';
|
|
44
|
-
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
45
|
-
import { Operation, OperationHandlerSet, OperationRegistry } from '@dxos/operation';
|
|
46
|
-
|
|
47
|
-
import { AiContextBinder, AiContextService, AiConversation, AiConversationService } from '../conversation';
|
|
48
|
-
import { ToolExecutionServices } from '../functions';
|
|
49
|
-
import { AgentService } from '../service';
|
|
50
|
-
import { CompleteBlock } from '../tracing';
|
|
51
|
-
|
|
52
|
-
interface TestLayerOptions {
|
|
53
|
-
aiServicePreset?: 'direct' | 'edge-local' | 'edge-remote';
|
|
54
|
-
model?: ModelName;
|
|
55
|
-
operationHandlers?: OperationHandlerSet.OperationHandlerSet | OperationHandlerSet.OperationHandlerSet[];
|
|
56
|
-
toolkits?: GenericToolkit.GenericToolkit[];
|
|
57
|
-
types?: Type.AnyEntity[];
|
|
58
|
-
blueprints?: Blueprint.Blueprint[];
|
|
59
|
-
credentials?: ServiceCredential[];
|
|
60
|
-
/*
|
|
61
|
-
* Tracing configuration.
|
|
62
|
-
* @default 'noop'
|
|
63
|
-
*/
|
|
64
|
-
tracing?: 'noop' | 'console' | 'pretty';
|
|
65
|
-
|
|
66
|
-
disableLlmMemoization?: boolean;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Core system prompt for the agent.
|
|
70
|
-
*/
|
|
71
|
-
systemPrompt?: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type AssistantTestServices =
|
|
75
|
-
// Convinience
|
|
76
|
-
| LanguageModel.LanguageModel
|
|
77
|
-
| Feed.FeedService
|
|
78
|
-
| CredentialsService
|
|
79
|
-
| AgentService.AgentService
|
|
80
|
-
| AiService.AiService
|
|
81
|
-
| Database.Service
|
|
82
|
-
| QueueService
|
|
83
|
-
// Registries
|
|
84
|
-
| Blueprint.RegistryService
|
|
85
|
-
| OperationRegistry.Service
|
|
86
|
-
| GenericToolkit.GenericToolkitProvider
|
|
87
|
-
| Operation.Service
|
|
88
|
-
// Core
|
|
89
|
-
| ProcessManager.ProcessManagerService
|
|
90
|
-
| Process.ProcessMonitorService
|
|
91
|
-
| Registry.AtomRegistry
|
|
92
|
-
// Should those be here?
|
|
93
|
-
| OperationHandlerSet.OperationHandlerProvider
|
|
94
|
-
| KeyValueStore.KeyValueStore
|
|
95
|
-
| ServiceResolver.ServiceResolver
|
|
96
|
-
| TracingService
|
|
97
|
-
| Trace.TraceService
|
|
98
|
-
| Trace.TraceSink
|
|
99
|
-
// Deprecated
|
|
100
|
-
| ToolExecutionService
|
|
101
|
-
| ToolResolverService
|
|
102
|
-
| FunctionInvocationService;
|
|
103
|
-
|
|
104
|
-
export const AssistantTestLayer = ({
|
|
105
|
-
aiServicePreset = 'direct',
|
|
106
|
-
model = '@anthropic/claude-opus-4-6',
|
|
107
|
-
operationHandlers = [],
|
|
108
|
-
toolkits = [],
|
|
109
|
-
types = [],
|
|
110
|
-
credentials = [],
|
|
111
|
-
tracing = 'noop',
|
|
112
|
-
disableLlmMemoization = false,
|
|
113
|
-
blueprints = [],
|
|
114
|
-
systemPrompt,
|
|
115
|
-
}: TestLayerOptions = {}): Layer.Layer<AssistantTestServices, never, TestContextService> => {
|
|
116
|
-
const toolkit = GenericToolkit.merge(...toolkits);
|
|
117
|
-
const operationHandlersSet = Array.isArray(operationHandlers)
|
|
118
|
-
? OperationHandlerSet.merge(...operationHandlers)
|
|
119
|
-
: operationHandlers;
|
|
120
|
-
types.push(Blueprint.Blueprint, Prompt.Prompt, Operation.PersistentOperation, Feed.Feed);
|
|
121
|
-
types = Array.dedupeWith(types, (a, b) => Type.getTypename(a) === Type.getTypename(b));
|
|
122
|
-
|
|
123
|
-
return Layer.empty.pipe(
|
|
124
|
-
Layer.provideMerge(ProcessManager.ProcessOperationInvoker.layer),
|
|
125
|
-
Layer.provideMerge(Trace.testTraceService({ meta: { processName: 'test' } })),
|
|
126
|
-
Layer.provideMerge(AgentService.layer({ systemPrompt })),
|
|
127
|
-
Layer.provideMerge(ProcessManager.layer({ idGenerator: ProcessManager.SequentialProcessIdGenerator })),
|
|
128
|
-
Layer.provideMerge(
|
|
129
|
-
// TODO(dmaretskyi): Refactor to be able to merge resovler layers, also consider service mesh achitecture.
|
|
130
|
-
Layer.effect(
|
|
131
|
-
ServiceResolver.ServiceResolver,
|
|
132
|
-
Effect.gen(function* () {
|
|
133
|
-
const services = yield* Effect.context<Database.Service | Feed.FeedService>().pipe(
|
|
134
|
-
Effect.map(Context.pick(Database.Service, Feed.FeedService)),
|
|
135
|
-
Effect.map(Layer.succeedContext),
|
|
136
|
-
);
|
|
137
|
-
// AiContextBinder.
|
|
138
|
-
return ServiceResolver.compose(
|
|
139
|
-
ServiceResolver.succeed(AiContextService, (context) =>
|
|
140
|
-
Effect.gen(function* () {
|
|
141
|
-
if (!context.conversation) {
|
|
142
|
-
return yield* Effect.fail(new ServiceNotAvailableError(AiContextService.key));
|
|
143
|
-
}
|
|
144
|
-
const feed = yield* Database.resolve(DXN.parse(context.conversation), Feed.Feed).pipe(Effect.orDie);
|
|
145
|
-
const runtime = yield* Effect.runtime<Feed.FeedService>();
|
|
146
|
-
const binder = yield* acquireReleaseResource(
|
|
147
|
-
() =>
|
|
148
|
-
new AiContextBinder({
|
|
149
|
-
feed,
|
|
150
|
-
runtime,
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
return { binder };
|
|
154
|
-
}).pipe(Effect.provide(services)),
|
|
155
|
-
),
|
|
156
|
-
// AiConversationService.
|
|
157
|
-
ServiceResolver.succeed(AiConversationService, (context) =>
|
|
158
|
-
Effect.gen(function* () {
|
|
159
|
-
if (!context.conversation) {
|
|
160
|
-
return yield* Effect.fail(new ServiceNotAvailableError(AiConversationService.key));
|
|
161
|
-
}
|
|
162
|
-
const feed = yield* Database.resolve(DXN.parse(context.conversation), Feed.Feed).pipe(Effect.orDie);
|
|
163
|
-
const runtime = yield* Effect.runtime<Feed.FeedService>();
|
|
164
|
-
const conversation = yield* acquireReleaseResource(
|
|
165
|
-
() =>
|
|
166
|
-
new AiConversation({
|
|
167
|
-
feed,
|
|
168
|
-
runtime,
|
|
169
|
-
}),
|
|
170
|
-
);
|
|
171
|
-
return conversation;
|
|
172
|
-
}).pipe(Effect.provide(services)),
|
|
173
|
-
),
|
|
174
|
-
yield* ServiceResolver.fromRequirements(
|
|
175
|
-
Database.Service,
|
|
176
|
-
GenericToolkit.GenericToolkitProvider,
|
|
177
|
-
Feed.FeedService,
|
|
178
|
-
AiService.AiService,
|
|
179
|
-
OperationRegistry.Service,
|
|
180
|
-
Blueprint.RegistryService,
|
|
181
|
-
FunctionInvocationService,
|
|
182
|
-
QueueService,
|
|
183
|
-
),
|
|
184
|
-
);
|
|
185
|
-
}),
|
|
186
|
-
),
|
|
187
|
-
),
|
|
188
|
-
Layer.provideMerge(Layer.mergeAll(OperationRegistry.layer, AiService.model(model), ToolExecutionServices)),
|
|
189
|
-
Layer.provideMerge(
|
|
190
|
-
FunctionInvocationServiceLayerTest({
|
|
191
|
-
functions: operationHandlersSet,
|
|
192
|
-
}),
|
|
193
|
-
),
|
|
194
|
-
Layer.provideMerge(
|
|
195
|
-
Layer.mergeAll(
|
|
196
|
-
TestAiService({ preset: aiServicePreset, disableMemoization: disableLlmMemoization }),
|
|
197
|
-
TestDatabaseLayer({
|
|
198
|
-
spaceKey: 'fixed',
|
|
199
|
-
types,
|
|
200
|
-
}),
|
|
201
|
-
CredentialsService.configuredLayer(credentials),
|
|
202
|
-
Match.value(tracing).pipe(
|
|
203
|
-
Match.when('noop', () => TracingService.layerNoop),
|
|
204
|
-
Match.when('console', () => TracingServiceExt.layerLogInfo()),
|
|
205
|
-
Match.when('pretty', () =>
|
|
206
|
-
TracingServiceExt.layerConsolePrettyPrint({
|
|
207
|
-
toolkit: (toolkits.length > 0 ? GenericToolkit.merge(...toolkits) : GenericToolkit.empty).toolkit as any,
|
|
208
|
-
}),
|
|
209
|
-
),
|
|
210
|
-
Match.exhaustive,
|
|
211
|
-
),
|
|
212
|
-
Match.value(tracing).pipe(
|
|
213
|
-
Match.when('noop', () => Trace.layerNoop),
|
|
214
|
-
Match.when('console', () => Trace.layerConsole),
|
|
215
|
-
Match.when('pretty', () => TraceSinkPretty()),
|
|
216
|
-
Match.exhaustive,
|
|
217
|
-
),
|
|
218
|
-
),
|
|
219
|
-
),
|
|
220
|
-
Layer.provideMerge(Layer.succeed(Blueprint.RegistryService, new Blueprint.Registry(blueprints))),
|
|
221
|
-
Layer.provideMerge(GenericToolkit.providerLayer(toolkit)),
|
|
222
|
-
Layer.provideMerge(OperationHandlerSet.provide(operationHandlersSet)),
|
|
223
|
-
Layer.provideMerge(KeyValueStore.layerMemory),
|
|
224
|
-
Layer.provideMerge(Registry.layer),
|
|
225
|
-
Layer.orDie,
|
|
226
|
-
);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
interface TestLayerWithTriggersOptions extends TestLayerOptions {}
|
|
230
|
-
|
|
231
|
-
export type AssistantTestServicesWithTriggers = AssistantTestServices | TriggerDispatcher | TriggerStateStore;
|
|
232
|
-
|
|
233
|
-
export const AssistantTestLayerWithTriggers = (
|
|
234
|
-
options: TestLayerWithTriggersOptions,
|
|
235
|
-
): Layer.Layer<AssistantTestServicesWithTriggers, never, TestContextService> =>
|
|
236
|
-
Layer.mergeAll(
|
|
237
|
-
AssistantTestLayer(options),
|
|
238
|
-
TriggerDispatcher.layer({ timeControl: 'manual', startingTime: new Date('2025-09-05T15:01:00.000Z') }).pipe(
|
|
239
|
-
Layer.provide(Registry.layer),
|
|
240
|
-
),
|
|
241
|
-
TriggerStateStore.layerMemory,
|
|
242
|
-
) as any;
|
|
243
|
-
|
|
244
|
-
const TraceSinkPretty = () =>
|
|
245
|
-
Layer.succeed(Trace.TraceSink, {
|
|
246
|
-
write: (message) => {
|
|
247
|
-
for (const event of message.events) {
|
|
248
|
-
if (Trace.isOfType(CompleteBlock, event)) {
|
|
249
|
-
const tag = message.meta.processName ?? `[${message.meta.pid ?? 'unknown'}]`;
|
|
250
|
-
console.log(`[${tag}] ${event.data.role.toUpperCase()}`);
|
|
251
|
-
new ConsolePrinter({ tag }).printContentBlock(event.data.block);
|
|
252
|
-
} else if (Trace.isOfType(Process.SpawnedEvent, event)) {
|
|
253
|
-
console.log(`[${message.meta.pid}] Process spawned: ${message.meta.processName}`);
|
|
254
|
-
} else if (Trace.isOfType(Process.ExitedEvent, event)) {
|
|
255
|
-
console.log(`[${message.meta.pid}] Process exited: ${event.data.outcome}`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
});
|