@framers/agentos-ext-endpoint-semantic 0.2.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/LICENSE +23 -0
- package/SKILL.md +74 -0
- package/dist/SemanticEndpointDetector.d.ts +186 -0
- package/dist/SemanticEndpointDetector.d.ts.map +1 -0
- package/dist/SemanticEndpointDetector.js +308 -0
- package/dist/SemanticEndpointDetector.js.map +1 -0
- package/dist/TurnCompletenessClassifier.d.ts +82 -0
- package/dist/TurnCompletenessClassifier.d.ts.map +1 -0
- package/dist/TurnCompletenessClassifier.js +130 -0
- package/dist/TurnCompletenessClassifier.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/manifest.json +8 -0
- package/package.json +42 -0
- package/src/SemanticEndpointDetector.ts +440 -0
- package/src/TurnCompletenessClassifier.ts +157 -0
- package/src/index.ts +125 -0
- package/src/types.ts +53 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Pack factory for the Semantic Endpoint Detector extension pack.
|
|
4
|
+
*
|
|
5
|
+
* ### Usage (direct)
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createSemanticEndpointDetector } from '@framers/agentos-ext-endpoint-semantic';
|
|
8
|
+
*
|
|
9
|
+
* const detector = createSemanticEndpointDetector(
|
|
10
|
+
* async (prompt) => myLlm(prompt),
|
|
11
|
+
* { timeoutMs: 400, minSilenceBeforeCheckMs: 600 }
|
|
12
|
+
* );
|
|
13
|
+
* detector.on('turn_complete', (evt) => console.log('Turn done:', evt.reason));
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* ### Usage (manifest-driven)
|
|
17
|
+
* ```json
|
|
18
|
+
* { "packs": [{ "module": "@framers/agentos-ext-endpoint-semantic" }] }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module endpoint-semantic
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { SemanticEndpointDetector } from './SemanticEndpointDetector.js';
|
|
25
|
+
import type { SemanticEndpointConfig } from './types.js';
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Local types (avoid hard runtime dep on @framers/agentos)
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/** Subset of ExtensionDescriptor required by this pack. */
|
|
32
|
+
interface ExtensionDescriptor {
|
|
33
|
+
id: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
payload: unknown;
|
|
36
|
+
enableByDefault?: boolean;
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Subset of ExtensionPack required by this pack. */
|
|
41
|
+
interface ExtensionPack {
|
|
42
|
+
id: string;
|
|
43
|
+
descriptors: ExtensionDescriptor[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Subset of ExtensionPackContext required by this pack. */
|
|
47
|
+
interface ExtensionPackContext {
|
|
48
|
+
getSecret?: (id: string) => string | undefined;
|
|
49
|
+
options?: Record<string, unknown>;
|
|
50
|
+
/** Runtime LLM call function supplied by the AgentOS extension manager. */
|
|
51
|
+
llmCall?: (prompt: string) => Promise<string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Kind constant matching packages/agentos/src/extensions/types.ts. */
|
|
55
|
+
const EXTENSION_KIND_ENDPOINT_DETECTOR = 'endpoint-detector';
|
|
56
|
+
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Factory helpers
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a standalone {@link SemanticEndpointDetector} instance.
|
|
63
|
+
*
|
|
64
|
+
* Use this when composing the detector programmatically outside of the
|
|
65
|
+
* AgentOS extension system.
|
|
66
|
+
*
|
|
67
|
+
* @param llmCall — Async function that sends a prompt string to an LLM and
|
|
68
|
+
* resolves with the raw response text.
|
|
69
|
+
* @param config — Optional configuration overrides.
|
|
70
|
+
* @returns A configured {@link SemanticEndpointDetector}.
|
|
71
|
+
*/
|
|
72
|
+
export function createSemanticEndpointDetector(
|
|
73
|
+
llmCall: (prompt: string) => Promise<string>,
|
|
74
|
+
config?: SemanticEndpointConfig,
|
|
75
|
+
): SemanticEndpointDetector {
|
|
76
|
+
return new SemanticEndpointDetector(llmCall, config);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* AgentOS manifest factory function.
|
|
81
|
+
*
|
|
82
|
+
* Returns an {@link ExtensionPack} containing a single `endpoint-detector`
|
|
83
|
+
* descriptor backed by {@link SemanticEndpointDetector}.
|
|
84
|
+
*
|
|
85
|
+
* The `llmCall` function must be provided via `context.llmCall`. When it is
|
|
86
|
+
* absent a no-op stub is used (the detector will always time out and fall back
|
|
87
|
+
* to silence-timeout behaviour).
|
|
88
|
+
*
|
|
89
|
+
* @param context — Pack context supplied by the extension manager.
|
|
90
|
+
* @returns A fully configured {@link ExtensionPack}.
|
|
91
|
+
*/
|
|
92
|
+
export function createExtensionPack(context: ExtensionPackContext): ExtensionPack {
|
|
93
|
+
const llmCall: (prompt: string) => Promise<string> =
|
|
94
|
+
context.llmCall ??
|
|
95
|
+
// Stub: always resolves to INCOMPLETE so the silence timeout takes over.
|
|
96
|
+
(() => Promise.resolve('INCOMPLETE (no llmCall provided)'));
|
|
97
|
+
|
|
98
|
+
const config: SemanticEndpointConfig = {
|
|
99
|
+
...(context.options as SemanticEndpointConfig | undefined),
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const detector = new SemanticEndpointDetector(llmCall, config);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
id: 'endpoint-semantic',
|
|
106
|
+
descriptors: [
|
|
107
|
+
{
|
|
108
|
+
id: 'endpoint-detector-semantic',
|
|
109
|
+
kind: EXTENSION_KIND_ENDPOINT_DETECTOR,
|
|
110
|
+
payload: detector,
|
|
111
|
+
enableByDefault: true,
|
|
112
|
+
metadata: { mode: 'semantic' },
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// Re-exports
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
export * from './types.js';
|
|
123
|
+
export { SemanticEndpointDetector } from './SemanticEndpointDetector.js';
|
|
124
|
+
export { TurnCompletenessClassifier } from './TurnCompletenessClassifier.js';
|
|
125
|
+
export type { ClassifyResult } from './TurnCompletenessClassifier.js';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file types.ts
|
|
3
|
+
* @description Public configuration types for the Semantic Endpoint Detector
|
|
4
|
+
* extension pack.
|
|
5
|
+
*
|
|
6
|
+
* @module endpoint-semantic/types
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for the {@link SemanticEndpointDetector}.
|
|
11
|
+
*
|
|
12
|
+
* All fields are optional — reasonable defaults are applied when omitted.
|
|
13
|
+
*/
|
|
14
|
+
export interface SemanticEndpointConfig {
|
|
15
|
+
/**
|
|
16
|
+
* LLM model identifier forwarded to the runtime LLM provider when performing
|
|
17
|
+
* turn-completeness classification. The exact string is passed through
|
|
18
|
+
* verbatim; its meaning is determined by whichever provider the caller
|
|
19
|
+
* supplies via the `llmCall` constructor argument.
|
|
20
|
+
*
|
|
21
|
+
* @example 'gpt-4o-mini'
|
|
22
|
+
* @example 'claude-haiku-3-5'
|
|
23
|
+
*/
|
|
24
|
+
model?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of milliseconds to wait for the LLM to return a
|
|
28
|
+
* classification before treating the result as a {@link ClassifyResult.TIMEOUT}.
|
|
29
|
+
* On timeout the detector falls back to the normal silence timeout behaviour.
|
|
30
|
+
*
|
|
31
|
+
* @defaultValue 500
|
|
32
|
+
*/
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Duration of silence (in ms) after a `speech_end` VAD event before the
|
|
37
|
+
* LLM classifier is invoked. Introducing a small delay avoids calling the
|
|
38
|
+
* LLM on micro-pauses that are immediately followed by resumed speech.
|
|
39
|
+
*
|
|
40
|
+
* @defaultValue 500
|
|
41
|
+
*/
|
|
42
|
+
minSilenceBeforeCheckMs?: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Duration (in ms) of silence after `speech_end` before the detector emits
|
|
46
|
+
* `turn_complete` with reason `'silence_timeout'` regardless of classifier
|
|
47
|
+
* output. Acts as a hard fallback when the LLM returns `INCOMPLETE` or times
|
|
48
|
+
* out.
|
|
49
|
+
*
|
|
50
|
+
* @defaultValue 1500
|
|
51
|
+
*/
|
|
52
|
+
silenceTimeoutMs?: number;
|
|
53
|
+
}
|