@absolutejs/voice 0.0.22-beta.3 → 0.0.22-beta.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/assistant.d.ts +20 -0
- package/dist/assistantMemory.d.ts +63 -0
- package/dist/fileStore.d.ts +5 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +206 -1
- package/dist/trace.d.ts +1 -1
- package/package.json +1 -1
package/dist/assistant.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VoiceAgent, type VoiceAgentModel, type VoiceAgentOptions, type VoiceAgentSquadOptions, type VoiceAgentTool } from './agent';
|
|
2
2
|
import { type VoiceOutcomeRecipeName, type VoiceOutcomeRecipeOptions } from './outcomeRecipes';
|
|
3
|
+
import { type VoiceAssistantMemoryHandle, type VoiceAssistantMemoryOptions } from './assistantMemory';
|
|
3
4
|
import type { VoiceNormalizedRouteConfig, VoiceOnTurnObjectHandler, VoiceRouteConfig, VoiceRouteResult, VoiceRuntimeOpsConfig, VoiceSessionRecord } from './types';
|
|
4
5
|
import type { StoredVoiceTraceEvent, VoiceTraceEventStore } from './trace';
|
|
5
6
|
export type VoiceAssistantPreset = VoiceOutcomeRecipeName;
|
|
@@ -12,6 +13,7 @@ export type VoiceAssistantArtifactPlan<TContext = unknown, TSession extends Voic
|
|
|
12
13
|
};
|
|
13
14
|
export type VoiceAssistantGuardrailInput<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = Parameters<VoiceOnTurnObjectHandler<TContext, TSession, TResult>>[0] & {
|
|
14
15
|
assistantId: string;
|
|
16
|
+
memory?: VoiceAssistantMemoryHandle;
|
|
15
17
|
};
|
|
16
18
|
export type VoiceAssistantOutputGuardrailInput<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = VoiceAssistantGuardrailInput<TContext, TSession, TResult> & {
|
|
17
19
|
result: VoiceRouteResult<TResult>;
|
|
@@ -29,6 +31,16 @@ export type VoiceAssistantVariant<TContext = unknown, TSession extends VoiceSess
|
|
|
29
31
|
tools?: Array<VoiceAgentTool<TContext, TSession, Record<string, unknown>, unknown, TResult>>;
|
|
30
32
|
weight?: number;
|
|
31
33
|
};
|
|
34
|
+
export type VoiceAssistantMemoryLifecycleInput<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = Parameters<VoiceOnTurnObjectHandler<TContext, TSession, TResult>>[0] & {
|
|
35
|
+
assistantId: string;
|
|
36
|
+
memory: VoiceAssistantMemoryHandle;
|
|
37
|
+
};
|
|
38
|
+
export type VoiceAssistantMemoryLifecycle<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = {
|
|
39
|
+
afterTurn?: (input: VoiceAssistantMemoryLifecycleInput<TContext, TSession, TResult> & {
|
|
40
|
+
result: VoiceRouteResult<TResult>;
|
|
41
|
+
}) => Promise<void> | void;
|
|
42
|
+
beforeTurn?: (input: VoiceAssistantMemoryLifecycleInput<TContext, TSession, TResult>) => Promise<void> | void;
|
|
43
|
+
};
|
|
32
44
|
export type VoiceAssistantExperimentResolverInput<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord> = {
|
|
33
45
|
assistantId: string;
|
|
34
46
|
context: TContext;
|
|
@@ -83,6 +95,8 @@ export type VoiceAssistantOptions<TContext = unknown, TSession extends VoiceSess
|
|
|
83
95
|
experiment?: VoiceAssistantExperiment<TContext, TSession, TResult>;
|
|
84
96
|
guardrails?: VoiceAssistantGuardrails<TContext, TSession, TResult>;
|
|
85
97
|
id: string;
|
|
98
|
+
memory?: VoiceAssistantMemoryOptions<TContext, TSession>;
|
|
99
|
+
memoryLifecycle?: VoiceAssistantMemoryLifecycle<TContext, TSession, TResult>;
|
|
86
100
|
ops?: VoiceRuntimeOpsConfig<TContext, TSession, TResult>;
|
|
87
101
|
trace?: VoiceAgentOptions<TContext, TSession, TResult>['trace'];
|
|
88
102
|
};
|
|
@@ -109,6 +123,12 @@ export type VoiceAssistantRunSummary = {
|
|
|
109
123
|
toolCalls: Record<string, number>;
|
|
110
124
|
transferCount: number;
|
|
111
125
|
variants: Record<string, number>;
|
|
126
|
+
memory: {
|
|
127
|
+
deletes: number;
|
|
128
|
+
gets: number;
|
|
129
|
+
lists: number;
|
|
130
|
+
sets: number;
|
|
131
|
+
};
|
|
112
132
|
};
|
|
113
133
|
export type VoiceAssistantRunsSummary = {
|
|
114
134
|
assistants: VoiceAssistantRunSummary[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { VoiceSessionRecord } from './types';
|
|
2
|
+
import type { VoiceTraceEventStore } from './trace';
|
|
3
|
+
export type VoiceAssistantMemoryRecord<TValue = unknown, TMetadata extends Record<string, unknown> = Record<string, unknown>> = {
|
|
4
|
+
assistantId: string;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
key: string;
|
|
7
|
+
metadata?: TMetadata;
|
|
8
|
+
namespace: string;
|
|
9
|
+
updatedAt: number;
|
|
10
|
+
value: TValue;
|
|
11
|
+
};
|
|
12
|
+
export type VoiceAssistantMemoryStore<TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord> = {
|
|
13
|
+
delete: (input: {
|
|
14
|
+
assistantId: string;
|
|
15
|
+
key: string;
|
|
16
|
+
namespace: string;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
get: (input: {
|
|
19
|
+
assistantId: string;
|
|
20
|
+
key: string;
|
|
21
|
+
namespace: string;
|
|
22
|
+
}) => Promise<TRecord | undefined>;
|
|
23
|
+
list: (input: {
|
|
24
|
+
assistantId: string;
|
|
25
|
+
namespace?: string;
|
|
26
|
+
}) => Promise<TRecord[]>;
|
|
27
|
+
set: (input: Omit<TRecord, 'createdAt' | 'updatedAt'> & {
|
|
28
|
+
createdAt?: number;
|
|
29
|
+
updatedAt?: number;
|
|
30
|
+
}) => Promise<TRecord>;
|
|
31
|
+
};
|
|
32
|
+
export type VoiceAssistantMemoryNamespaceInput<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord> = {
|
|
33
|
+
assistantId: string;
|
|
34
|
+
context: TContext;
|
|
35
|
+
session: TSession;
|
|
36
|
+
};
|
|
37
|
+
export type VoiceAssistantMemoryOptions<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord> = {
|
|
38
|
+
namespace: string | ((input: VoiceAssistantMemoryNamespaceInput<TContext, TSession>) => Promise<string> | string);
|
|
39
|
+
store: VoiceAssistantMemoryStore<TRecord>;
|
|
40
|
+
};
|
|
41
|
+
export type VoiceAssistantMemoryBinding<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord> = VoiceAssistantMemoryOptions<TContext, TSession, TRecord>;
|
|
42
|
+
export type VoiceAssistantMemoryHandle<TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord> = {
|
|
43
|
+
delete: (key: string) => Promise<void>;
|
|
44
|
+
get: <TValue = unknown>(key: string) => Promise<TValue | undefined>;
|
|
45
|
+
list: () => Promise<TRecord[]>;
|
|
46
|
+
namespace: string;
|
|
47
|
+
set: <TValue = unknown>(key: string, value: TValue, metadata?: Record<string, unknown>) => Promise<TRecord>;
|
|
48
|
+
};
|
|
49
|
+
export declare const createVoiceAssistantMemoryRecord: <TValue = unknown, TMetadata extends Record<string, unknown> = Record<string, unknown>>(input: Omit<VoiceAssistantMemoryRecord<TValue, TMetadata>, "createdAt" | "updatedAt"> & {
|
|
50
|
+
createdAt?: number;
|
|
51
|
+
updatedAt?: number;
|
|
52
|
+
}) => VoiceAssistantMemoryRecord<TValue, TMetadata>;
|
|
53
|
+
export declare const createVoiceMemoryAssistantMemoryStore: <TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord>() => VoiceAssistantMemoryStore<TRecord>;
|
|
54
|
+
export declare const resolveVoiceAssistantMemoryNamespace: <TContext, TSession extends VoiceSessionRecord>(input: VoiceAssistantMemoryNamespaceInput<TContext, TSession> & {
|
|
55
|
+
memory: VoiceAssistantMemoryOptions<TContext, TSession>;
|
|
56
|
+
}) => Promise<string>;
|
|
57
|
+
export declare const createVoiceAssistantMemoryHandle: <TContext, TSession extends VoiceSessionRecord, TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord>(input: {
|
|
58
|
+
assistantId: string;
|
|
59
|
+
context: TContext;
|
|
60
|
+
memory: VoiceAssistantMemoryOptions<TContext, TSession, TRecord>;
|
|
61
|
+
session: TSession;
|
|
62
|
+
trace?: VoiceTraceEventStore;
|
|
63
|
+
}) => Promise<VoiceAssistantMemoryHandle<TRecord>>;
|
package/dist/fileStore.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type VoiceAssistantMemoryRecord, type VoiceAssistantMemoryStore } from './assistantMemory';
|
|
1
2
|
import { type StoredVoiceTraceEvent, type VoiceTraceSinkDeliveryRecord, type VoiceTraceSinkDeliveryStore, type VoiceTraceEventStore } from './trace';
|
|
2
3
|
import type { StoredVoiceIntegrationEvent, StoredVoiceExternalObjectMap, StoredVoiceOpsTask, VoiceExternalObjectMap, VoiceExternalObjectMapStore, VoiceIntegrationEvent, VoiceIntegrationEventStore, VoiceOpsTask, VoiceOpsTaskStore } from './ops';
|
|
3
4
|
import type { StoredVoiceCallReviewArtifact, VoiceCallReviewArtifact, VoiceCallReviewStore } from './testing/review';
|
|
@@ -6,9 +7,10 @@ export type VoiceFileStoreOptions = {
|
|
|
6
7
|
directory: string;
|
|
7
8
|
pretty?: boolean;
|
|
8
9
|
};
|
|
9
|
-
export type VoiceFileRuntimeStorage<TSession extends VoiceSessionRecord = VoiceSessionRecord, TReview extends StoredVoiceCallReviewArtifact = StoredVoiceCallReviewArtifact, TTask extends StoredVoiceOpsTask = StoredVoiceOpsTask, TEvent extends StoredVoiceIntegrationEvent = StoredVoiceIntegrationEvent, TMapping extends StoredVoiceExternalObjectMap = StoredVoiceExternalObjectMap, TTrace extends StoredVoiceTraceEvent = StoredVoiceTraceEvent, TTraceDelivery extends VoiceTraceSinkDeliveryRecord = VoiceTraceSinkDeliveryRecord> = {
|
|
10
|
+
export type VoiceFileRuntimeStorage<TSession extends VoiceSessionRecord = VoiceSessionRecord, TReview extends StoredVoiceCallReviewArtifact = StoredVoiceCallReviewArtifact, TTask extends StoredVoiceOpsTask = StoredVoiceOpsTask, TEvent extends StoredVoiceIntegrationEvent = StoredVoiceIntegrationEvent, TMapping extends StoredVoiceExternalObjectMap = StoredVoiceExternalObjectMap, TTrace extends StoredVoiceTraceEvent = StoredVoiceTraceEvent, TTraceDelivery extends VoiceTraceSinkDeliveryRecord = VoiceTraceSinkDeliveryRecord, TMemory extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord> = {
|
|
10
11
|
events: VoiceIntegrationEventStore<TEvent>;
|
|
11
12
|
externalObjects: VoiceExternalObjectMapStore<TMapping>;
|
|
13
|
+
memories: VoiceAssistantMemoryStore<TMemory>;
|
|
12
14
|
reviews: VoiceCallReviewStore<TReview>;
|
|
13
15
|
session: VoiceSessionStore<TSession>;
|
|
14
16
|
tasks: VoiceOpsTaskStore<TTask>;
|
|
@@ -22,7 +24,8 @@ export declare const createVoiceFileIntegrationEventStore: <TEvent extends Store
|
|
|
22
24
|
export declare const createVoiceFileExternalObjectMapStore: <TMapping extends StoredVoiceExternalObjectMap = StoredVoiceExternalObjectMap>(options: VoiceFileStoreOptions) => VoiceExternalObjectMapStore<TMapping>;
|
|
23
25
|
export declare const createVoiceFileTraceEventStore: <TEvent extends StoredVoiceTraceEvent = StoredVoiceTraceEvent>(options: VoiceFileStoreOptions) => VoiceTraceEventStore<TEvent>;
|
|
24
26
|
export declare const createVoiceFileTraceSinkDeliveryStore: <TDelivery extends VoiceTraceSinkDeliveryRecord = VoiceTraceSinkDeliveryRecord>(options: VoiceFileStoreOptions) => VoiceTraceSinkDeliveryStore<TDelivery>;
|
|
25
|
-
export declare const
|
|
27
|
+
export declare const createVoiceFileAssistantMemoryStore: <TRecord extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord>(options: VoiceFileStoreOptions) => VoiceAssistantMemoryStore<TRecord>;
|
|
28
|
+
export declare const createVoiceFileRuntimeStorage: <TSession extends VoiceSessionRecord = VoiceSessionRecord, TReview extends StoredVoiceCallReviewArtifact = StoredVoiceCallReviewArtifact, TTask extends StoredVoiceOpsTask = StoredVoiceOpsTask, TEvent extends StoredVoiceIntegrationEvent = StoredVoiceIntegrationEvent, TMapping extends StoredVoiceExternalObjectMap = StoredVoiceExternalObjectMap, TTrace extends StoredVoiceTraceEvent = StoredVoiceTraceEvent, TTraceDelivery extends VoiceTraceSinkDeliveryRecord = VoiceTraceSinkDeliveryRecord, TMemory extends VoiceAssistantMemoryRecord = VoiceAssistantMemoryRecord>(options: VoiceFileStoreOptions) => VoiceFileRuntimeStorage<TSession, TReview, TTask, TEvent, TMapping, TTrace, TTraceDelivery, TMemory>;
|
|
26
29
|
export declare const createStoredVoiceCallReviewArtifact: <TArtifact extends VoiceCallReviewArtifact = VoiceCallReviewArtifact>(id: string, artifact: TArtifact) => TArtifact & {
|
|
27
30
|
id: string;
|
|
28
31
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { voice } from './plugin';
|
|
2
2
|
export { createVoiceAssistant, createVoiceExperiment, summarizeVoiceAssistantRuns } from './assistant';
|
|
3
3
|
export { createVoiceAgent, createVoiceAgentSquad, createVoiceAgentTool } from './agent';
|
|
4
|
-
export { createStoredVoiceCallReviewArtifact, createStoredVoiceExternalObjectMap, createStoredVoiceIntegrationEvent, createStoredVoiceOpsTask, createVoiceFileExternalObjectMapStore, createVoiceFileIntegrationEventStore, createVoiceFileReviewStore, createVoiceFileRuntimeStorage, createVoiceFileSessionStore, createVoiceFileTaskStore, createVoiceFileTraceSinkDeliveryStore, createVoiceFileTraceEventStore } from './fileStore';
|
|
4
|
+
export { createStoredVoiceCallReviewArtifact, createStoredVoiceExternalObjectMap, createStoredVoiceIntegrationEvent, createStoredVoiceOpsTask, createVoiceFileExternalObjectMapStore, createVoiceFileAssistantMemoryStore, createVoiceFileIntegrationEventStore, createVoiceFileReviewStore, createVoiceFileRuntimeStorage, createVoiceFileSessionStore, createVoiceFileTaskStore, createVoiceFileTraceSinkDeliveryStore, createVoiceFileTraceEventStore } from './fileStore';
|
|
5
|
+
export { createVoiceAssistantMemoryHandle, createVoiceAssistantMemoryRecord, createVoiceMemoryAssistantMemoryStore, resolveVoiceAssistantMemoryNamespace } from './assistantMemory';
|
|
5
6
|
export { buildVoiceTraceReplay, createVoiceMemoryTraceSinkDeliveryStore, createVoiceTraceHTTPSink, createVoiceMemoryTraceEventStore, createVoiceTraceSinkDeliveryId, createVoiceTraceSinkDeliveryRecord, createVoiceTraceSinkStore, createVoiceTraceEvent, createVoiceTraceEventId, deliverVoiceTraceEventsToSinks, evaluateVoiceTrace, exportVoiceTrace, filterVoiceTraceEvents, pruneVoiceTraceEvents, redactVoiceTraceEvent, redactVoiceTraceEvents, redactVoiceTraceText, renderVoiceTraceHTML, renderVoiceTraceMarkdown, resolveVoiceTraceRedactionOptions, selectVoiceTraceEventsForPrune, summarizeVoiceTrace } from './trace';
|
|
6
7
|
export { createVoiceSQLiteExternalObjectMapStore, createVoiceSQLiteIntegrationEventStore, createVoiceSQLiteReviewStore, createVoiceSQLiteRuntimeStorage, createVoiceSQLiteSessionStore, createVoiceSQLiteTaskStore, createVoiceSQLiteTraceSinkDeliveryStore, createVoiceSQLiteTraceEventStore } from './sqliteStore';
|
|
7
8
|
export { createVoicePostgresExternalObjectMapStore, createVoicePostgresIntegrationEventStore, createVoicePostgresReviewStore, createVoicePostgresRuntimeStorage, createVoicePostgresSessionStore, createVoicePostgresTaskStore, createVoicePostgresTraceSinkDeliveryStore, createVoicePostgresTraceEventStore } from './postgresStore';
|
|
@@ -22,7 +23,8 @@ export { conditionAudioChunk, resolveAudioConditioningConfig } from './audioCond
|
|
|
22
23
|
export { resolveVoiceRuntimePreset } from './presets';
|
|
23
24
|
export { resolveTurnDetectionConfig, TURN_PROFILE_DEFAULTS } from './turnProfiles';
|
|
24
25
|
export { createVoiceCallReviewFromLiveTelephonyReport, createVoiceCallReviewRecorder, renderVoiceCallReviewHTML, renderVoiceCallReviewMarkdown } from './testing/review';
|
|
25
|
-
export type { VoiceAssistant, VoiceAssistantArtifactPlan, VoiceAssistantExperiment, VoiceAssistantExperimentOptions, VoiceAssistantGuardrailInput, VoiceAssistantGuardrails, VoiceAssistantOptions, VoiceAssistantOutputGuardrailInput, VoiceAssistantPreset, VoiceAssistantRunsSummary, VoiceAssistantRunSummary, VoiceAssistantVariant } from './assistant';
|
|
26
|
+
export type { VoiceAssistant, VoiceAssistantArtifactPlan, VoiceAssistantExperiment, VoiceAssistantExperimentOptions, VoiceAssistantGuardrailInput, VoiceAssistantGuardrails, VoiceAssistantMemoryLifecycle, VoiceAssistantMemoryLifecycleInput, VoiceAssistantOptions, VoiceAssistantOutputGuardrailInput, VoiceAssistantPreset, VoiceAssistantRunsSummary, VoiceAssistantRunSummary, VoiceAssistantVariant } from './assistant';
|
|
27
|
+
export type { VoiceAssistantMemoryBinding, VoiceAssistantMemoryHandle, VoiceAssistantMemoryOptions, VoiceAssistantMemoryRecord, VoiceAssistantMemoryStore } from './assistantMemory';
|
|
26
28
|
export type { VoiceAgent, VoiceAgentMessage, VoiceAgentMessageRole, VoiceAgentModel, VoiceAgentModelInput, VoiceAgentModelOutput, VoiceAgentOptions, VoiceAgentRunResult, VoiceAgentSquadOptions, VoiceAgentTool, VoiceAgentToolCall, VoiceAgentToolResult } from './agent';
|
|
27
29
|
export type { VoiceOpsRuntime, VoiceOpsRuntimeConfig, VoiceOpsRuntimeSummary, VoiceOpsRuntimeSinkWorkerConfig, VoiceOpsRuntimeTaskWorkerConfig, VoiceOpsRuntimeTickResult, VoiceOpsRuntimeWebhookWorkerConfig } from './opsRuntime';
|
|
28
30
|
export type { VoiceOpsPresetName, VoiceOpsPresetOverrides, VoiceResolvedOpsPreset } from './opsPresets';
|
package/dist/index.js
CHANGED
|
@@ -5594,6 +5594,112 @@ var resolveVoiceOutcomeRecipe = (name, options = {}) => {
|
|
|
5594
5594
|
};
|
|
5595
5595
|
};
|
|
5596
5596
|
|
|
5597
|
+
// src/assistantMemory.ts
|
|
5598
|
+
var createMemoryId = (input) => `${input.assistantId}:${input.namespace}:${input.key}`;
|
|
5599
|
+
var createVoiceAssistantMemoryRecord = (input) => {
|
|
5600
|
+
const now = Date.now();
|
|
5601
|
+
return {
|
|
5602
|
+
...input,
|
|
5603
|
+
createdAt: input.createdAt ?? input.updatedAt ?? now,
|
|
5604
|
+
updatedAt: input.updatedAt ?? now
|
|
5605
|
+
};
|
|
5606
|
+
};
|
|
5607
|
+
var createVoiceMemoryAssistantMemoryStore = () => {
|
|
5608
|
+
const records = new Map;
|
|
5609
|
+
return {
|
|
5610
|
+
delete: async (input) => {
|
|
5611
|
+
records.delete(createMemoryId(input));
|
|
5612
|
+
},
|
|
5613
|
+
get: async (input) => records.get(createMemoryId(input)),
|
|
5614
|
+
list: async (input) => [...records.values()].filter((record) => record.assistantId === input.assistantId && (input.namespace === undefined || record.namespace === input.namespace)).sort((left, right) => right.updatedAt - left.updatedAt),
|
|
5615
|
+
set: async (input) => {
|
|
5616
|
+
const id = createMemoryId(input);
|
|
5617
|
+
const existing = records.get(id);
|
|
5618
|
+
const record = createVoiceAssistantMemoryRecord({
|
|
5619
|
+
...input,
|
|
5620
|
+
createdAt: input.createdAt ?? existing?.createdAt,
|
|
5621
|
+
updatedAt: input.updatedAt
|
|
5622
|
+
});
|
|
5623
|
+
records.set(id, record);
|
|
5624
|
+
return record;
|
|
5625
|
+
}
|
|
5626
|
+
};
|
|
5627
|
+
};
|
|
5628
|
+
var resolveVoiceAssistantMemoryNamespace = async (input) => typeof input.memory.namespace === "function" ? await input.memory.namespace(input) : input.memory.namespace;
|
|
5629
|
+
var createVoiceAssistantMemoryHandle = async (input) => {
|
|
5630
|
+
const namespace = await resolveVoiceAssistantMemoryNamespace({
|
|
5631
|
+
assistantId: input.assistantId,
|
|
5632
|
+
context: input.context,
|
|
5633
|
+
memory: input.memory,
|
|
5634
|
+
session: input.session
|
|
5635
|
+
});
|
|
5636
|
+
const trace = async (event) => {
|
|
5637
|
+
await input.trace?.append({
|
|
5638
|
+
at: Date.now(),
|
|
5639
|
+
payload: {
|
|
5640
|
+
assistantId: input.assistantId,
|
|
5641
|
+
namespace,
|
|
5642
|
+
...event
|
|
5643
|
+
},
|
|
5644
|
+
scenarioId: input.session.scenarioId,
|
|
5645
|
+
sessionId: input.session.id,
|
|
5646
|
+
type: "assistant.memory"
|
|
5647
|
+
});
|
|
5648
|
+
};
|
|
5649
|
+
return {
|
|
5650
|
+
delete: async (key) => {
|
|
5651
|
+
await input.memory.store.delete({
|
|
5652
|
+
assistantId: input.assistantId,
|
|
5653
|
+
key,
|
|
5654
|
+
namespace
|
|
5655
|
+
});
|
|
5656
|
+
await trace({
|
|
5657
|
+
action: "delete",
|
|
5658
|
+
key
|
|
5659
|
+
});
|
|
5660
|
+
},
|
|
5661
|
+
get: async (key) => {
|
|
5662
|
+
const record = await input.memory.store.get({
|
|
5663
|
+
assistantId: input.assistantId,
|
|
5664
|
+
key,
|
|
5665
|
+
namespace
|
|
5666
|
+
});
|
|
5667
|
+
await trace({
|
|
5668
|
+
action: "get",
|
|
5669
|
+
found: Boolean(record),
|
|
5670
|
+
key
|
|
5671
|
+
});
|
|
5672
|
+
return record?.value;
|
|
5673
|
+
},
|
|
5674
|
+
list: async () => {
|
|
5675
|
+
const records = await input.memory.store.list({
|
|
5676
|
+
assistantId: input.assistantId,
|
|
5677
|
+
namespace
|
|
5678
|
+
});
|
|
5679
|
+
await trace({
|
|
5680
|
+
action: "list",
|
|
5681
|
+
count: records.length
|
|
5682
|
+
});
|
|
5683
|
+
return records;
|
|
5684
|
+
},
|
|
5685
|
+
namespace,
|
|
5686
|
+
set: async (key, value, metadata) => {
|
|
5687
|
+
const record = await input.memory.store.set({
|
|
5688
|
+
assistantId: input.assistantId,
|
|
5689
|
+
key,
|
|
5690
|
+
metadata,
|
|
5691
|
+
namespace,
|
|
5692
|
+
value
|
|
5693
|
+
});
|
|
5694
|
+
await trace({
|
|
5695
|
+
action: "set",
|
|
5696
|
+
key
|
|
5697
|
+
});
|
|
5698
|
+
return record;
|
|
5699
|
+
}
|
|
5700
|
+
};
|
|
5701
|
+
};
|
|
5702
|
+
|
|
5597
5703
|
// src/assistant.ts
|
|
5598
5704
|
var hashString = (value) => {
|
|
5599
5705
|
let hash = 2166136261;
|
|
@@ -5742,12 +5848,35 @@ var createVoiceAssistant = (options) => {
|
|
|
5742
5848
|
});
|
|
5743
5849
|
}
|
|
5744
5850
|
const onTurn = async (input) => {
|
|
5851
|
+
const memory = options.memory ? await createVoiceAssistantMemoryHandle({
|
|
5852
|
+
assistantId: options.id,
|
|
5853
|
+
context: input.context,
|
|
5854
|
+
memory: options.memory,
|
|
5855
|
+
session: input.session,
|
|
5856
|
+
trace: options.trace
|
|
5857
|
+
}) : undefined;
|
|
5745
5858
|
const guardrailInput = {
|
|
5746
5859
|
...input,
|
|
5747
|
-
assistantId: options.id
|
|
5860
|
+
assistantId: options.id,
|
|
5861
|
+
memory
|
|
5748
5862
|
};
|
|
5863
|
+
if (memory) {
|
|
5864
|
+
await options.memoryLifecycle?.beforeTurn?.({
|
|
5865
|
+
...input,
|
|
5866
|
+
assistantId: options.id,
|
|
5867
|
+
memory
|
|
5868
|
+
});
|
|
5869
|
+
}
|
|
5749
5870
|
const blocked = await options.guardrails?.beforeTurn?.(guardrailInput);
|
|
5750
5871
|
if (blocked) {
|
|
5872
|
+
if (memory) {
|
|
5873
|
+
await options.memoryLifecycle?.afterTurn?.({
|
|
5874
|
+
...input,
|
|
5875
|
+
assistantId: options.id,
|
|
5876
|
+
memory,
|
|
5877
|
+
result: blocked
|
|
5878
|
+
});
|
|
5879
|
+
}
|
|
5751
5880
|
await appendAssistantTrace({
|
|
5752
5881
|
assistantId: options.id,
|
|
5753
5882
|
event: {
|
|
@@ -5797,6 +5926,14 @@ var createVoiceAssistant = (options) => {
|
|
|
5797
5926
|
result
|
|
5798
5927
|
});
|
|
5799
5928
|
const finalResult = guarded ?? result;
|
|
5929
|
+
if (memory) {
|
|
5930
|
+
await options.memoryLifecycle?.afterTurn?.({
|
|
5931
|
+
...input,
|
|
5932
|
+
assistantId: options.id,
|
|
5933
|
+
memory,
|
|
5934
|
+
result: finalResult
|
|
5935
|
+
});
|
|
5936
|
+
}
|
|
5800
5937
|
if (guarded) {
|
|
5801
5938
|
await appendAssistantTrace({
|
|
5802
5939
|
assistantId: options.id,
|
|
@@ -5864,6 +6001,12 @@ var summarizeVoiceAssistantRuns = async (input) => {
|
|
|
5864
6001
|
escalationCount: 0,
|
|
5865
6002
|
experiments: {},
|
|
5866
6003
|
guardrailCount: 0,
|
|
6004
|
+
memory: {
|
|
6005
|
+
deletes: 0,
|
|
6006
|
+
gets: 0,
|
|
6007
|
+
lists: 0,
|
|
6008
|
+
sets: 0
|
|
6009
|
+
},
|
|
5867
6010
|
outcomes: {},
|
|
5868
6011
|
runCount: 0,
|
|
5869
6012
|
sessionIds: new Set,
|
|
@@ -5919,6 +6062,24 @@ var summarizeVoiceAssistantRuns = async (input) => {
|
|
|
5919
6062
|
const summary = getSummary(assistantId);
|
|
5920
6063
|
summary.guardrailCount += 1;
|
|
5921
6064
|
}
|
|
6065
|
+
for (const event of events.filter((event2) => event2.type === "assistant.memory")) {
|
|
6066
|
+
const assistantId = typeof event.payload.assistantId === "string" ? event.payload.assistantId : "unknown";
|
|
6067
|
+
const summary = getSummary(assistantId);
|
|
6068
|
+
switch (event.payload.action) {
|
|
6069
|
+
case "delete":
|
|
6070
|
+
summary.memory.deletes += 1;
|
|
6071
|
+
break;
|
|
6072
|
+
case "get":
|
|
6073
|
+
summary.memory.gets += 1;
|
|
6074
|
+
break;
|
|
6075
|
+
case "list":
|
|
6076
|
+
summary.memory.lists += 1;
|
|
6077
|
+
break;
|
|
6078
|
+
case "set":
|
|
6079
|
+
summary.memory.sets += 1;
|
|
6080
|
+
break;
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
5922
6083
|
const assistants = [...byAssistant.values()].map(({ elapsedCount, elapsedTotal, sessionIds, ...summary }) => ({
|
|
5923
6084
|
...summary,
|
|
5924
6085
|
averageElapsedMs: elapsedCount > 0 ? Math.round(elapsedTotal / elapsedCount) : undefined,
|
|
@@ -6613,6 +6774,7 @@ var listJsonFiles = async (directory) => {
|
|
|
6613
6774
|
};
|
|
6614
6775
|
var encodeStoreId = (id) => `${encodeURIComponent(id)}.json`;
|
|
6615
6776
|
var resolveFilePath = (directory, id) => join(directory, encodeStoreId(id));
|
|
6777
|
+
var createMemoryStoreId = (input) => `${input.assistantId}:${input.namespace}:${input.key}`;
|
|
6616
6778
|
var readJsonFile = async (path) => JSON.parse(await readFile(path, "utf8"));
|
|
6617
6779
|
var writeJsonFile = async (path, value, options) => {
|
|
6618
6780
|
await mkdir(options.directory, {
|
|
@@ -6832,6 +6994,40 @@ var createVoiceFileTraceSinkDeliveryStore = (options) => {
|
|
|
6832
6994
|
};
|
|
6833
6995
|
return { get, list, remove, set };
|
|
6834
6996
|
};
|
|
6997
|
+
var createVoiceFileAssistantMemoryStore = (options) => {
|
|
6998
|
+
const get = async (input) => {
|
|
6999
|
+
const path = resolveFilePath(options.directory, createMemoryStoreId(input));
|
|
7000
|
+
try {
|
|
7001
|
+
return await readJsonFile(path);
|
|
7002
|
+
} catch (error) {
|
|
7003
|
+
if (error.code === "ENOENT") {
|
|
7004
|
+
return;
|
|
7005
|
+
}
|
|
7006
|
+
throw error;
|
|
7007
|
+
}
|
|
7008
|
+
};
|
|
7009
|
+
const list = async (input) => {
|
|
7010
|
+
const files = await listJsonFiles(options.directory);
|
|
7011
|
+
const records = await Promise.all(files.map((file) => readJsonFile(file)));
|
|
7012
|
+
return records.filter((record) => record.assistantId === input.assistantId && (input.namespace === undefined || record.namespace === input.namespace)).sort((left, right) => right.updatedAt - left.updatedAt);
|
|
7013
|
+
};
|
|
7014
|
+
const set = async (input) => {
|
|
7015
|
+
const existing = await get(input);
|
|
7016
|
+
const record = createVoiceAssistantMemoryRecord({
|
|
7017
|
+
...input,
|
|
7018
|
+
createdAt: input.createdAt ?? existing?.createdAt,
|
|
7019
|
+
updatedAt: input.updatedAt
|
|
7020
|
+
});
|
|
7021
|
+
await writeJsonFile(resolveFilePath(options.directory, createMemoryStoreId(record)), record, options);
|
|
7022
|
+
return record;
|
|
7023
|
+
};
|
|
7024
|
+
const remove = async (input) => {
|
|
7025
|
+
await rm(resolveFilePath(options.directory, createMemoryStoreId(input)), {
|
|
7026
|
+
force: true
|
|
7027
|
+
});
|
|
7028
|
+
};
|
|
7029
|
+
return { delete: remove, get, list, set };
|
|
7030
|
+
};
|
|
6835
7031
|
var createVoiceFileRuntimeStorage = (options) => ({
|
|
6836
7032
|
events: createVoiceFileIntegrationEventStore({
|
|
6837
7033
|
...options,
|
|
@@ -6841,6 +7037,10 @@ var createVoiceFileRuntimeStorage = (options) => ({
|
|
|
6841
7037
|
...options,
|
|
6842
7038
|
directory: join(options.directory, "external-objects")
|
|
6843
7039
|
}),
|
|
7040
|
+
memories: createVoiceFileAssistantMemoryStore({
|
|
7041
|
+
...options,
|
|
7042
|
+
directory: join(options.directory, "memories")
|
|
7043
|
+
}),
|
|
6844
7044
|
reviews: createVoiceFileReviewStore({
|
|
6845
7045
|
...options,
|
|
6846
7046
|
directory: join(options.directory, "reviews")
|
|
@@ -9339,6 +9539,7 @@ export {
|
|
|
9339
9539
|
resolveVoiceOpsTaskAssignment,
|
|
9340
9540
|
resolveVoiceOpsTaskAgeBucket,
|
|
9341
9541
|
resolveVoiceOpsPreset,
|
|
9542
|
+
resolveVoiceAssistantMemoryNamespace,
|
|
9342
9543
|
resolveTurnDetectionConfig,
|
|
9343
9544
|
resolveAudioConditioningConfig,
|
|
9344
9545
|
requeueVoiceOpsTask,
|
|
@@ -9414,6 +9615,7 @@ export {
|
|
|
9414
9615
|
createVoiceMemoryTraceSinkDeliveryStore,
|
|
9415
9616
|
createVoiceMemoryTraceEventStore,
|
|
9416
9617
|
createVoiceMemoryStore,
|
|
9618
|
+
createVoiceMemoryAssistantMemoryStore,
|
|
9417
9619
|
createVoiceLinearIssueUpdateSink,
|
|
9418
9620
|
createVoiceLinearIssueSyncSinks,
|
|
9419
9621
|
createVoiceLinearIssueSink,
|
|
@@ -9433,6 +9635,7 @@ export {
|
|
|
9433
9635
|
createVoiceFileReviewStore,
|
|
9434
9636
|
createVoiceFileIntegrationEventStore,
|
|
9435
9637
|
createVoiceFileExternalObjectMapStore,
|
|
9638
|
+
createVoiceFileAssistantMemoryStore,
|
|
9436
9639
|
createVoiceExternalObjectMapId,
|
|
9437
9640
|
createVoiceExternalObjectMap,
|
|
9438
9641
|
createVoiceExperiment,
|
|
@@ -9441,6 +9644,8 @@ export {
|
|
|
9441
9644
|
createVoiceCallReviewFromLiveTelephonyReport,
|
|
9442
9645
|
createVoiceCallCompletedEvent,
|
|
9443
9646
|
createVoiceCRMActivitySink,
|
|
9647
|
+
createVoiceAssistantMemoryRecord,
|
|
9648
|
+
createVoiceAssistantMemoryHandle,
|
|
9444
9649
|
createVoiceAssistant,
|
|
9445
9650
|
createVoiceAgentTool,
|
|
9446
9651
|
createVoiceAgentSquad,
|
package/dist/trace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type VoiceTraceEventType = 'assistant.guardrail' | 'assistant.run' | 'agent.handoff' | 'agent.model' | 'agent.result' | 'agent.tool' | 'call.lifecycle' | 'session.error' | 'turn.assistant' | 'turn.committed' | 'turn.cost' | 'turn.transcript';
|
|
1
|
+
export type VoiceTraceEventType = 'assistant.guardrail' | 'assistant.memory' | 'assistant.run' | 'agent.handoff' | 'agent.model' | 'agent.result' | 'agent.tool' | 'call.lifecycle' | 'session.error' | 'turn.assistant' | 'turn.committed' | 'turn.cost' | 'turn.transcript';
|
|
2
2
|
export type VoiceTraceEvent<TPayload extends Record<string, unknown> = Record<string, unknown>> = {
|
|
3
3
|
at: number;
|
|
4
4
|
id?: string;
|