@primo-ai/core 0.1.2 → 0.1.4
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/agent.d.ts +13 -1
- package/dist/agent.js +128 -4
- package/dist/checkpoint-store.d.ts +0 -1
- package/dist/checkpoint-store.js +0 -1
- package/dist/concurrency-controller.d.ts +0 -1
- package/dist/concurrency-controller.js +0 -1
- package/dist/config-merge.d.ts +0 -1
- package/dist/config-merge.js +0 -1
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -1
- package/dist/context-builder.d.ts +0 -1
- package/dist/context-builder.js +0 -1
- package/dist/dynamic-resolver.d.ts +0 -1
- package/dist/dynamic-resolver.js +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/event-bus.d.ts +1 -1
- package/dist/event-bus.js +8 -1
- package/dist/event-system.d.ts +0 -1
- package/dist/event-system.js +0 -1
- package/dist/fallback-runner.d.ts +0 -1
- package/dist/fallback-runner.js +0 -1
- package/dist/gateways/builtin-gateway.d.ts +0 -1
- package/dist/gateways/builtin-gateway.js +0 -1
- package/dist/gateways/gateway-chain.d.ts +4 -1
- package/dist/gateways/gateway-chain.js +6 -1
- package/dist/gateways/openai-compatible-gateway.d.ts +0 -1
- package/dist/gateways/openai-compatible-gateway.js +0 -1
- package/dist/harness.d.ts +0 -1
- package/dist/harness.js +0 -1
- package/dist/hook-manager.d.ts +0 -1
- package/dist/hook-manager.js +0 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/llm-invoker.d.ts +3 -4
- package/dist/llm-invoker.js +10 -10
- package/dist/loop-orchestrator.d.ts +0 -1
- package/dist/loop-orchestrator.js +10 -1
- package/dist/model-factory.d.ts +4 -1
- package/dist/model-factory.js +3 -1
- package/dist/model-profile.d.ts +0 -1
- package/dist/model-profile.js +0 -1
- package/dist/model-resolver.d.ts +0 -1
- package/dist/model-resolver.js +0 -1
- package/dist/parse-model.d.ts +0 -1
- package/dist/parse-model.js +0 -1
- package/dist/pending-permission.d.ts +16 -0
- package/dist/pending-permission.js +24 -0
- package/dist/pipeline.d.ts +3 -3
- package/dist/pipeline.js +29 -4
- package/dist/plugin-manager.d.ts +0 -1
- package/dist/plugin-manager.js +12 -13
- package/dist/processors/build-context.d.ts +0 -1
- package/dist/processors/build-context.js +0 -1
- package/dist/processors/evaluate-iteration.d.ts +0 -1
- package/dist/processors/evaluate-iteration.js +7 -4
- package/dist/processors/execute-tools.d.ts +0 -1
- package/dist/processors/execute-tools.js +0 -1
- package/dist/processors/gate-tool.d.ts +0 -1
- package/dist/processors/gate-tool.js +0 -1
- package/dist/processors/index.d.ts +0 -1
- package/dist/processors/index.js +0 -1
- package/dist/processors/invoke-llm.d.ts +0 -1
- package/dist/processors/invoke-llm.js +0 -1
- package/dist/processors/prepare-step.d.ts +0 -1
- package/dist/processors/prepare-step.js +0 -1
- package/dist/processors/process-input.d.ts +0 -1
- package/dist/processors/process-input.js +0 -1
- package/dist/processors/process-output.d.ts +0 -1
- package/dist/processors/process-output.js +0 -1
- package/dist/processors/process-step-output.d.ts +0 -1
- package/dist/processors/process-step-output.js +0 -1
- package/dist/processors/provider-history-compat.d.ts +0 -1
- package/dist/processors/provider-history-compat.js +0 -1
- package/dist/provider-capabilities.d.ts +0 -1
- package/dist/provider-capabilities.js +0 -1
- package/dist/retry.d.ts +0 -1
- package/dist/retry.js +0 -1
- package/dist/serialize.d.ts +0 -1
- package/dist/serialize.js +0 -1
- package/dist/session-manager.d.ts +0 -1
- package/dist/session-manager.js +0 -1
- package/dist/session-persistence.d.ts +0 -1
- package/dist/session-persistence.js +0 -1
- package/dist/session-storage-sqlite.d.ts +41 -0
- package/dist/session-storage-sqlite.js +239 -0
- package/dist/session-storage.d.ts +6 -1
- package/dist/session-storage.js +65 -1
- package/dist/state-machine.d.ts +0 -1
- package/dist/state-machine.js +0 -1
- package/dist/storage-replay-backend.d.ts +0 -1
- package/dist/storage-replay-backend.js +0 -1
- package/dist/sub-agent.d.ts +0 -1
- package/dist/sub-agent.js +0 -1
- package/dist/task-manager.d.ts +0 -1
- package/dist/task-manager.js +6 -3
- package/dist/token-counter.d.ts +0 -1
- package/dist/token-counter.js +0 -1
- package/dist/tool-registry.d.ts +0 -1
- package/dist/tool-registry.js +0 -1
- package/package.json +8 -4
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js.map +0 -1
- package/dist/checkpoint-store.d.ts.map +0 -1
- package/dist/checkpoint-store.js.map +0 -1
- package/dist/concurrency-controller.d.ts.map +0 -1
- package/dist/concurrency-controller.js.map +0 -1
- package/dist/config-merge.d.ts.map +0 -1
- package/dist/config-merge.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/context-builder.d.ts.map +0 -1
- package/dist/context-builder.js.map +0 -1
- package/dist/dynamic-resolver.d.ts.map +0 -1
- package/dist/dynamic-resolver.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/event-bus.d.ts.map +0 -1
- package/dist/event-bus.js.map +0 -1
- package/dist/event-system.d.ts.map +0 -1
- package/dist/event-system.js.map +0 -1
- package/dist/fallback-runner.d.ts.map +0 -1
- package/dist/fallback-runner.js.map +0 -1
- package/dist/gateways/builtin-gateway.d.ts.map +0 -1
- package/dist/gateways/builtin-gateway.js.map +0 -1
- package/dist/gateways/gateway-chain.d.ts.map +0 -1
- package/dist/gateways/gateway-chain.js.map +0 -1
- package/dist/gateways/openai-compatible-gateway.d.ts.map +0 -1
- package/dist/gateways/openai-compatible-gateway.js.map +0 -1
- package/dist/harness.d.ts.map +0 -1
- package/dist/harness.js.map +0 -1
- package/dist/hook-manager.d.ts.map +0 -1
- package/dist/hook-manager.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/llm-invoker.d.ts.map +0 -1
- package/dist/llm-invoker.js.map +0 -1
- package/dist/loop-orchestrator.d.ts.map +0 -1
- package/dist/loop-orchestrator.js.map +0 -1
- package/dist/model-factory.d.ts.map +0 -1
- package/dist/model-factory.js.map +0 -1
- package/dist/model-profile.d.ts.map +0 -1
- package/dist/model-profile.js.map +0 -1
- package/dist/model-resolver.d.ts.map +0 -1
- package/dist/model-resolver.js.map +0 -1
- package/dist/parse-model.d.ts.map +0 -1
- package/dist/parse-model.js.map +0 -1
- package/dist/pipeline.d.ts.map +0 -1
- package/dist/pipeline.js.map +0 -1
- package/dist/plugin-manager.d.ts.map +0 -1
- package/dist/plugin-manager.js.map +0 -1
- package/dist/processors/build-context.d.ts.map +0 -1
- package/dist/processors/build-context.js.map +0 -1
- package/dist/processors/evaluate-iteration.d.ts.map +0 -1
- package/dist/processors/evaluate-iteration.js.map +0 -1
- package/dist/processors/execute-tools.d.ts.map +0 -1
- package/dist/processors/execute-tools.js.map +0 -1
- package/dist/processors/gate-tool.d.ts.map +0 -1
- package/dist/processors/gate-tool.js.map +0 -1
- package/dist/processors/index.d.ts.map +0 -1
- package/dist/processors/index.js.map +0 -1
- package/dist/processors/invoke-llm.d.ts.map +0 -1
- package/dist/processors/invoke-llm.js.map +0 -1
- package/dist/processors/prepare-step.d.ts.map +0 -1
- package/dist/processors/prepare-step.js.map +0 -1
- package/dist/processors/process-input.d.ts.map +0 -1
- package/dist/processors/process-input.js.map +0 -1
- package/dist/processors/process-output.d.ts.map +0 -1
- package/dist/processors/process-output.js.map +0 -1
- package/dist/processors/process-step-output.d.ts.map +0 -1
- package/dist/processors/process-step-output.js.map +0 -1
- package/dist/processors/provider-history-compat.d.ts.map +0 -1
- package/dist/processors/provider-history-compat.js.map +0 -1
- package/dist/provider-capabilities.d.ts.map +0 -1
- package/dist/provider-capabilities.js.map +0 -1
- package/dist/retry.d.ts.map +0 -1
- package/dist/retry.js.map +0 -1
- package/dist/serialize.d.ts.map +0 -1
- package/dist/serialize.js.map +0 -1
- package/dist/session-manager.d.ts.map +0 -1
- package/dist/session-manager.js.map +0 -1
- package/dist/session-persistence.d.ts.map +0 -1
- package/dist/session-persistence.js.map +0 -1
- package/dist/session-storage.d.ts.map +0 -1
- package/dist/session-storage.js.map +0 -1
- package/dist/state-machine.d.ts.map +0 -1
- package/dist/state-machine.js.map +0 -1
- package/dist/storage-replay-backend.d.ts.map +0 -1
- package/dist/storage-replay-backend.js.map +0 -1
- package/dist/sub-agent.d.ts.map +0 -1
- package/dist/sub-agent.js.map +0 -1
- package/dist/task-manager.d.ts.map +0 -1
- package/dist/task-manager.js.map +0 -1
- package/dist/token-counter.d.ts.map +0 -1
- package/dist/token-counter.js.map +0 -1
- package/dist/tool-registry.d.ts.map +0 -1
- package/dist/tool-registry.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class PermissionManager {
|
|
2
|
+
pending = new Map();
|
|
3
|
+
awaitDecision(permission) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
this.pending.set(permission.permissionId, { resolve, permission });
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
resolve(permissionId, approved) {
|
|
9
|
+
const entry = this.pending.get(permissionId);
|
|
10
|
+
if (!entry)
|
|
11
|
+
throw new Error(`Permission not found: ${permissionId}`);
|
|
12
|
+
entry.resolve(approved);
|
|
13
|
+
this.pending.delete(permissionId);
|
|
14
|
+
}
|
|
15
|
+
list() {
|
|
16
|
+
return Array.from(this.pending.values()).map(e => e.permission);
|
|
17
|
+
}
|
|
18
|
+
getBySession(sessionId) {
|
|
19
|
+
return this.list().filter(p => p.sessionId === sessionId);
|
|
20
|
+
}
|
|
21
|
+
get(permissionId) {
|
|
22
|
+
return this.pending.get(permissionId)?.permission;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AbortSignal, PipelineContext, Processor, StageName, StreamEvent, SuspensionSignal, Tracer } from '@primo-ai/sdk';
|
|
1
|
+
import type { AbortSignal, ErrorResult, PipelineContext, Processor, StageName, StreamEvent, SuspensionSignal, Tracer } from '@primo-ai/sdk';
|
|
2
2
|
import type { HookManager } from './hook-manager.js';
|
|
3
|
-
export type RunResult = PipelineContext | AbortSignal | SuspensionSignal;
|
|
3
|
+
export type RunResult = PipelineContext | AbortSignal | SuspensionSignal | ErrorResult;
|
|
4
4
|
export interface PipelineRunnerOptions {
|
|
5
5
|
tracer?: Tracer;
|
|
6
6
|
hookManager?: HookManager;
|
|
@@ -23,6 +23,6 @@ export declare class PipelineRunner {
|
|
|
23
23
|
private executeStage;
|
|
24
24
|
private isAbort;
|
|
25
25
|
private isSuspend;
|
|
26
|
+
private isError;
|
|
26
27
|
private consumeStream;
|
|
27
28
|
}
|
|
28
|
-
//# sourceMappingURL=pipeline.d.ts.map
|
package/dist/pipeline.js
CHANGED
|
@@ -100,6 +100,17 @@ export class PipelineRunner {
|
|
|
100
100
|
rootSpan.end();
|
|
101
101
|
return stageResult;
|
|
102
102
|
}
|
|
103
|
+
if (this.isError(stageResult)) {
|
|
104
|
+
stageSpan.end();
|
|
105
|
+
if (this.hookManager) {
|
|
106
|
+
try {
|
|
107
|
+
await this.hookManager.invoke('error', { error: stageResult.error, stage: stageResult.stage }, {});
|
|
108
|
+
}
|
|
109
|
+
catch { /* hook error must not mask original */ }
|
|
110
|
+
}
|
|
111
|
+
rootSpan.end();
|
|
112
|
+
return stageResult;
|
|
113
|
+
}
|
|
103
114
|
ctx = stageResult;
|
|
104
115
|
ctx = await this.consumeStream(ctx);
|
|
105
116
|
// Fire llm.after after stream is consumed (response is now available)
|
|
@@ -155,6 +166,18 @@ export class PipelineRunner {
|
|
|
155
166
|
yield { type: 'suspended', suspensionId: stageResult.suspensionId, reason: stageResult.reason, checkpoint: stageResult.checkpoint };
|
|
156
167
|
return;
|
|
157
168
|
}
|
|
169
|
+
if (this.isError(stageResult)) {
|
|
170
|
+
stageSpan.end();
|
|
171
|
+
if (this.hookManager) {
|
|
172
|
+
try {
|
|
173
|
+
await this.hookManager.invoke('error', { error: stageResult.error, stage: stageResult.stage }, {});
|
|
174
|
+
}
|
|
175
|
+
catch { /* hook error must not mask original */ }
|
|
176
|
+
}
|
|
177
|
+
rootSpan.end();
|
|
178
|
+
yield { type: 'error', error: stageResult.error, stage: stageResult.stage, recoverable: stageResult.recoverable };
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
158
181
|
ctx = stageResult;
|
|
159
182
|
const fullStream = ctx.iteration.fullStream;
|
|
160
183
|
if (fullStream) {
|
|
@@ -197,7 +220,7 @@ export class PipelineRunner {
|
|
|
197
220
|
response: chunks.join('') || ctx.iteration.response || '',
|
|
198
221
|
pendingToolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
199
222
|
reasoningContent,
|
|
200
|
-
tokenUsage: usage ?? pendingUsage,
|
|
223
|
+
tokenUsage: usage ?? pendingUsage ?? undefined,
|
|
201
224
|
fullStream: undefined,
|
|
202
225
|
usagePromise: undefined,
|
|
203
226
|
reasoningPromise: undefined,
|
|
@@ -242,7 +265,7 @@ export class PipelineRunner {
|
|
|
242
265
|
iteration: { ...currentCtx.iteration, span: stageSpan },
|
|
243
266
|
});
|
|
244
267
|
const result = await processor.execute(ctxWithSpan);
|
|
245
|
-
if ('type' in result && (result.type === 'abort' || result.type === 'suspend')) {
|
|
268
|
+
if ('type' in result && (result.type === 'abort' || result.type === 'suspend' || result.type === 'error')) {
|
|
246
269
|
return result;
|
|
247
270
|
}
|
|
248
271
|
currentCtx = deepFreeze({ ...result });
|
|
@@ -259,6 +282,9 @@ export class PipelineRunner {
|
|
|
259
282
|
isSuspend(result) {
|
|
260
283
|
return 'type' in result && result.type === 'suspend';
|
|
261
284
|
}
|
|
285
|
+
isError(result) {
|
|
286
|
+
return 'type' in result && result.type === 'error';
|
|
287
|
+
}
|
|
262
288
|
async consumeStream(ctx) {
|
|
263
289
|
const fullStream = ctx.iteration.fullStream;
|
|
264
290
|
if (!fullStream)
|
|
@@ -275,7 +301,7 @@ export class PipelineRunner {
|
|
|
275
301
|
response: result.chunks.join('') || ctx.iteration.response,
|
|
276
302
|
pendingToolCalls: result.toolCalls.length > 0 ? result.toolCalls : undefined,
|
|
277
303
|
reasoningContent,
|
|
278
|
-
tokenUsage: result.usage ?? pendingUsage,
|
|
304
|
+
tokenUsage: result.usage ?? pendingUsage ?? undefined,
|
|
279
305
|
fullStream: undefined,
|
|
280
306
|
usagePromise: undefined,
|
|
281
307
|
reasoningPromise: undefined,
|
|
@@ -283,4 +309,3 @@ export class PipelineRunner {
|
|
|
283
309
|
});
|
|
284
310
|
}
|
|
285
311
|
}
|
|
286
|
-
//# sourceMappingURL=pipeline.js.map
|
package/dist/plugin-manager.d.ts
CHANGED
package/dist/plugin-manager.js
CHANGED
|
@@ -52,10 +52,9 @@ export class PluginManager {
|
|
|
52
52
|
this.initializePlugin(factory);
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
55
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
56
|
+
this.eventBus.emit('plugin:load_error', { source: filePath, error });
|
|
57
|
+
this.errors.push({ source: filePath, error });
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
initializePlugin(factory) {
|
|
@@ -97,12 +96,14 @@ export class PluginManager {
|
|
|
97
96
|
this.resourceInstances.set(resource.id, instance);
|
|
98
97
|
}
|
|
99
98
|
catch (err) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
99
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
100
|
+
this.eventBus.emit('plugin:resource_init_error', { source: `resource:${resource.id}`, error });
|
|
101
|
+
this.errors.push({ source: `resource:${resource.id}`, error });
|
|
104
102
|
}
|
|
105
103
|
}
|
|
104
|
+
if (this.errors.length > 0) {
|
|
105
|
+
throw new AggregateError(this.errors.map(e => e.error), `Plugin initialization failed for ${this.errors.length} resource(s): ${this.errors.map(e => e.source).join(', ')}`);
|
|
106
|
+
}
|
|
106
107
|
}
|
|
107
108
|
_shutdown = false;
|
|
108
109
|
async shutdown() {
|
|
@@ -116,10 +117,9 @@ export class PluginManager {
|
|
|
116
117
|
await resource.stop(instance);
|
|
117
118
|
}
|
|
118
119
|
catch (err) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
120
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
121
|
+
this.eventBus.emit('plugin:shutdown_error', { source: `resource:${resource.id}`, error });
|
|
122
|
+
this.errors.push({ source: `resource:${resource.id}`, error });
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
this.resourceInstances.clear();
|
|
@@ -145,4 +145,3 @@ export class PluginManager {
|
|
|
145
145
|
return impl;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
//# sourceMappingURL=plugin-manager.js.map
|
|
@@ -10,4 +10,3 @@ export declare function createEvaluateIterationProcessor(deps?: EvaluateIteratio
|
|
|
10
10
|
* @deprecated Use `createEvaluateIterationProcessor({ eventBus })` for full functionality.
|
|
11
11
|
*/
|
|
12
12
|
export declare const evaluateIterationProcessor: Processor;
|
|
13
|
-
//# sourceMappingURL=evaluate-iteration.d.ts.map
|
|
@@ -24,10 +24,14 @@ export function createEvaluateIterationProcessor(deps) {
|
|
|
24
24
|
stage: 'evaluateIteration',
|
|
25
25
|
execute: async (ctx) => {
|
|
26
26
|
const prevTotal = ctx.session.totalTokenUsage ?? { input: 0, output: 0 };
|
|
27
|
-
const iterUsage = ctx.iteration.tokenUsage
|
|
27
|
+
const iterUsage = ctx.iteration.tokenUsage;
|
|
28
|
+
if (!iterUsage) {
|
|
29
|
+
eventBus?.emit('token:usage_unavailable', { step: ctx.iteration.step });
|
|
30
|
+
}
|
|
31
|
+
const safeUsage = iterUsage ?? { input: 0, output: 0 };
|
|
28
32
|
const totalTokenUsage = {
|
|
29
|
-
input: prevTotal.input +
|
|
30
|
-
output: prevTotal.output +
|
|
33
|
+
input: prevTotal.input + safeUsage.input,
|
|
34
|
+
output: prevTotal.output + safeUsage.output,
|
|
31
35
|
};
|
|
32
36
|
const totalTokens = totalTokenUsage.input + totalTokenUsage.output;
|
|
33
37
|
const requiredTools = ctx.agent.config.requiredTools;
|
|
@@ -193,4 +197,3 @@ export function createEvaluateIterationProcessor(deps) {
|
|
|
193
197
|
* @deprecated Use `createEvaluateIterationProcessor({ eventBus })` for full functionality.
|
|
194
198
|
*/
|
|
195
199
|
export const evaluateIterationProcessor = createEvaluateIterationProcessor();
|
|
196
|
-
//# sourceMappingURL=evaluate-iteration.js.map
|
|
@@ -7,4 +7,3 @@ export { gateToolExtensionPoint } from './gate-tool.js';
|
|
|
7
7
|
export { createExecuteToolsProcessor } from './execute-tools.js';
|
|
8
8
|
export { createEvaluateIterationProcessor, evaluateIterationProcessor } from './evaluate-iteration.js';
|
|
9
9
|
export { processOutputProcessor } from './process-output.js';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/processors/index.js
CHANGED
|
@@ -7,4 +7,3 @@ export { gateToolExtensionPoint } from './gate-tool.js';
|
|
|
7
7
|
export { createExecuteToolsProcessor } from './execute-tools.js';
|
|
8
8
|
export { createEvaluateIterationProcessor, evaluateIterationProcessor } from './evaluate-iteration.js';
|
|
9
9
|
export { processOutputProcessor } from './process-output.js';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -4,4 +4,3 @@ export declare const BUILTIN_COMPAT_RULES: CompatRule[];
|
|
|
4
4
|
export declare function applyPreemptiveRules(messages: unknown[], modelString: string, capabilities: ProviderCapabilities, rules?: CompatRule[]): unknown[];
|
|
5
5
|
/** Try reactive rules against an API error. Returns fixed history + diff, or null. */
|
|
6
6
|
export declare function applyReactiveRules(history: import('@primo-ai/sdk').Message[], modelString: string, error: unknown, rules?: CompatRule[]): import('@primo-ai/sdk').CompatResult | null;
|
|
7
|
-
//# sourceMappingURL=provider-history-compat.d.ts.map
|
package/dist/retry.d.ts
CHANGED
package/dist/retry.js
CHANGED
package/dist/serialize.d.ts
CHANGED
package/dist/serialize.js
CHANGED
package/dist/session-manager.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SessionEvent, SessionRecord, SessionStorage, SessionStatus, Message } from '@primo-ai/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* SqliteSessionStorage — SQLite-backed implementation of SessionStorage.
|
|
4
|
+
*
|
|
5
|
+
* Uses `better-sqlite3` as an **optional** dependency. The module is loaded
|
|
6
|
+
* dynamically so projects that only need FilesystemSessionStorage never pay
|
|
7
|
+
* the cost (or install penalty) of the native binding.
|
|
8
|
+
*
|
|
9
|
+
* Pass `:memory:` as dbPath for an in-memory database (useful for tests).
|
|
10
|
+
*/
|
|
11
|
+
export declare class SqliteSessionStorage implements SessionStorage {
|
|
12
|
+
private db;
|
|
13
|
+
private stmtInsertEvent;
|
|
14
|
+
private stmtSelectEvents;
|
|
15
|
+
private stmtSelectSession;
|
|
16
|
+
private stmtUpsertSession;
|
|
17
|
+
private stmtDeleteSession;
|
|
18
|
+
private stmtSelectSessionsByStatus;
|
|
19
|
+
private stmtSelectSessionsByParent;
|
|
20
|
+
private stmtSelectAllSessions;
|
|
21
|
+
private stmtNextSeq;
|
|
22
|
+
constructor(dbPath: string);
|
|
23
|
+
private initSchema;
|
|
24
|
+
private prepareStatements;
|
|
25
|
+
append(sessionId: string, event: SessionEvent): Promise<void>;
|
|
26
|
+
read(sessionId: string): AsyncIterable<SessionEvent>;
|
|
27
|
+
list(filter?: {
|
|
28
|
+
parentSessionId?: string;
|
|
29
|
+
status?: SessionStatus;
|
|
30
|
+
}): Promise<SessionRecord[]>;
|
|
31
|
+
updateMeta(sessionId: string, meta: Partial<SessionRecord>): Promise<void>;
|
|
32
|
+
get(sessionId: string): Promise<SessionRecord | undefined>;
|
|
33
|
+
delete(sessionId: string): Promise<void>;
|
|
34
|
+
getMessages(sessionId: string, options?: {
|
|
35
|
+
limit?: number;
|
|
36
|
+
before?: string;
|
|
37
|
+
}): Promise<Message[]>;
|
|
38
|
+
/** Close the underlying database connection. */
|
|
39
|
+
close(): void;
|
|
40
|
+
private rowToRecord;
|
|
41
|
+
}
|