mojentic 1.4.0 → 1.5.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.
Files changed (67) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/llm/broker.d.ts +7 -2
  6. package/dist/llm/broker.d.ts.map +1 -1
  7. package/dist/llm/broker.js +65 -65
  8. package/dist/llm/broker.js.map +1 -1
  9. package/dist/llm/gateways/openai-model-registry.d.ts.map +1 -1
  10. package/dist/llm/gateways/openai-model-registry.js +34 -1
  11. package/dist/llm/gateways/openai-model-registry.js.map +1 -1
  12. package/dist/llm/tools/index.d.ts +1 -0
  13. package/dist/llm/tools/index.d.ts.map +1 -1
  14. package/dist/llm/tools/index.js +1 -0
  15. package/dist/llm/tools/index.js.map +1 -1
  16. package/dist/llm/tools/runner.d.ts +89 -0
  17. package/dist/llm/tools/runner.d.ts.map +1 -0
  18. package/dist/llm/tools/runner.js +130 -0
  19. package/dist/llm/tools/runner.js.map +1 -0
  20. package/dist/llm/tools/tool.d.ts +18 -3
  21. package/dist/llm/tools/tool.d.ts.map +1 -1
  22. package/dist/llm/tools/tool.js.map +1 -1
  23. package/dist/realtime/broker.d.ts +40 -0
  24. package/dist/realtime/broker.d.ts.map +1 -0
  25. package/dist/realtime/broker.js +74 -0
  26. package/dist/realtime/broker.js.map +1 -0
  27. package/dist/realtime/config.d.ts +134 -0
  28. package/dist/realtime/config.d.ts.map +1 -0
  29. package/dist/realtime/config.js +23 -0
  30. package/dist/realtime/config.js.map +1 -0
  31. package/dist/realtime/events.d.ts +146 -0
  32. package/dist/realtime/events.d.ts.map +1 -0
  33. package/dist/realtime/events.js +10 -0
  34. package/dist/realtime/events.js.map +1 -0
  35. package/dist/realtime/gateway.d.ts +48 -0
  36. package/dist/realtime/gateway.d.ts.map +1 -0
  37. package/dist/realtime/gateway.js +9 -0
  38. package/dist/realtime/gateway.js.map +1 -0
  39. package/dist/realtime/index.d.ts +14 -0
  40. package/dist/realtime/index.d.ts.map +1 -0
  41. package/dist/realtime/index.js +30 -0
  42. package/dist/realtime/index.js.map +1 -0
  43. package/dist/realtime/openai-gateway.d.ts +39 -0
  44. package/dist/realtime/openai-gateway.d.ts.map +1 -0
  45. package/dist/realtime/openai-gateway.js +154 -0
  46. package/dist/realtime/openai-gateway.js.map +1 -0
  47. package/dist/realtime/schemas.d.ts +333 -0
  48. package/dist/realtime/schemas.d.ts.map +1 -0
  49. package/dist/realtime/schemas.js +243 -0
  50. package/dist/realtime/schemas.js.map +1 -0
  51. package/dist/realtime/session.d.ts +115 -0
  52. package/dist/realtime/session.d.ts.map +1 -0
  53. package/dist/realtime/session.js +715 -0
  54. package/dist/realtime/session.js.map +1 -0
  55. package/dist/realtime/transport.d.ts +87 -0
  56. package/dist/realtime/transport.d.ts.map +1 -0
  57. package/dist/realtime/transport.js +115 -0
  58. package/dist/realtime/transport.js.map +1 -0
  59. package/dist/tracer/tracerEvents.d.ts +23 -0
  60. package/dist/tracer/tracerEvents.d.ts.map +1 -1
  61. package/dist/tracer/tracerEvents.js +40 -1
  62. package/dist/tracer/tracerEvents.js.map +1 -1
  63. package/dist/tracer/tracerSystem.d.ts +16 -0
  64. package/dist/tracer/tracerSystem.d.ts.map +1 -1
  65. package/dist/tracer/tracerSystem.js +22 -0
  66. package/dist/tracer/tracerSystem.js.map +1 -1
  67. package/package.json +20 -10
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ /**
3
+ * Tool runner abstraction for executing batches of tool calls.
4
+ *
5
+ * Provides pluggable execution strategies (serial, parallel) so brokers
6
+ * can stay independent of concurrency policy.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ParallelToolRunner = exports.SerialToolRunner = void 0;
10
+ const error_1 = require("../../error");
11
+ const NOT_FOUND_ERROR = (name) => new Error(`Tool ${name} not found`);
12
+ async function executeOne(call, tools, context) {
13
+ const start = Date.now();
14
+ context?.onCallStart?.(call);
15
+ const tool = tools.find((t) => t.matches(call.name));
16
+ if (!tool) {
17
+ const outcome = {
18
+ id: call.id,
19
+ name: call.name,
20
+ ok: false,
21
+ error: NOT_FOUND_ERROR(call.name),
22
+ durationMs: Date.now() - start,
23
+ };
24
+ context?.onCallComplete?.(outcome);
25
+ return outcome;
26
+ }
27
+ try {
28
+ const ctx = { signal: context?.signal };
29
+ const result = await tool.run(call.args, ctx);
30
+ const durationMs = Date.now() - start;
31
+ const outcome = (0, error_1.isOk)(result)
32
+ ? { id: call.id, name: call.name, ok: true, result: result.value, durationMs }
33
+ : { id: call.id, name: call.name, ok: false, error: result.error, durationMs };
34
+ context?.onCallComplete?.(outcome);
35
+ return outcome;
36
+ }
37
+ catch (err) {
38
+ const error = err instanceof Error ? err : new Error(String(err));
39
+ const outcome = {
40
+ id: call.id,
41
+ name: call.name,
42
+ ok: false,
43
+ error,
44
+ durationMs: Date.now() - start,
45
+ };
46
+ context?.onCallComplete?.(outcome);
47
+ return outcome;
48
+ }
49
+ }
50
+ /**
51
+ * Executes tool calls one at a time in input order.
52
+ *
53
+ * This is the default for {@link LlmBroker} for backward compatibility and
54
+ * for cases where you want predictable, stepwise debugging.
55
+ */
56
+ class SerialToolRunner {
57
+ async runBatch(calls, tools, context) {
58
+ const outcomes = [];
59
+ for (const call of calls) {
60
+ if (context?.signal?.aborted) {
61
+ outcomes.push({
62
+ id: call.id,
63
+ name: call.name,
64
+ ok: false,
65
+ error: new Error('Tool batch aborted'),
66
+ durationMs: 0,
67
+ });
68
+ continue;
69
+ }
70
+ outcomes.push(await executeOne(call, tools, context));
71
+ }
72
+ return outcomes;
73
+ }
74
+ }
75
+ exports.SerialToolRunner = SerialToolRunner;
76
+ /**
77
+ * Executes tool calls concurrently with a bounded fan-out.
78
+ *
79
+ * `maxConcurrency` defaults to 4 — high enough to win on typical realtime
80
+ * turns (2–3 concurrent function calls) but low enough that unbounded fan-out
81
+ * into rate-limited APIs (web search, embeddings) doesn't punish users.
82
+ */
83
+ class ParallelToolRunner {
84
+ maxConcurrency;
85
+ constructor(maxConcurrency = 4) {
86
+ this.maxConcurrency = maxConcurrency;
87
+ if (!Number.isFinite(maxConcurrency) || maxConcurrency < 1) {
88
+ throw new Error(`maxConcurrency must be a positive integer, got ${maxConcurrency}`);
89
+ }
90
+ }
91
+ async runBatch(calls, tools, context) {
92
+ if (calls.length === 0) {
93
+ return [];
94
+ }
95
+ const outcomes = new Array(calls.length);
96
+ let cursor = 0;
97
+ const workers = [];
98
+ const workerCount = Math.min(this.maxConcurrency, calls.length);
99
+ for (let w = 0; w < workerCount; w++) {
100
+ workers.push((async () => {
101
+ while (true) {
102
+ const idx = cursor++;
103
+ if (idx >= calls.length) {
104
+ return;
105
+ }
106
+ // idx is bounded by calls.length above; safe array access.
107
+ // eslint-disable-next-line security/detect-object-injection
108
+ const call = calls[idx];
109
+ if (context?.signal?.aborted) {
110
+ // eslint-disable-next-line security/detect-object-injection
111
+ outcomes[idx] = {
112
+ id: call.id,
113
+ name: call.name,
114
+ ok: false,
115
+ error: new Error('Tool batch aborted'),
116
+ durationMs: 0,
117
+ };
118
+ continue;
119
+ }
120
+ // eslint-disable-next-line security/detect-object-injection
121
+ outcomes[idx] = await executeOne(call, tools, context);
122
+ }
123
+ })());
124
+ }
125
+ await Promise.all(workers);
126
+ return outcomes;
127
+ }
128
+ }
129
+ exports.ParallelToolRunner = ParallelToolRunner;
130
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/llm/tools/runner.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAA2C;AA6D3C,MAAM,eAAe,GAAG,CAAC,IAAY,EAAS,EAAE,CAAC,IAAI,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,CAAC;AAErF,KAAK,UAAU,UAAU,CACvB,IAAuB,EACvB,KAAyB,EACzB,OAAmC;IAEnC,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AAI,EAAE,IAAI,CAAC,IAAI;4BACf,EAAE,EAAE,KAAK;4BACT,KAAK,EAAE,IAAI,KAAK,CAAC,oBAAoB,CAAC;4BACtC,UAAU,EAAE,CAAC;yBACd,CAAC;wBACF,SAAS;oBACX,CAAC;oBACD,4DAA4D;oBAC5D,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC,CAAC,EAAE,CACL,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAtDD,gDAsDC"}
@@ -37,14 +37,29 @@ export type ToolArgs = Record<string, unknown>;
37
37
  * Result of a tool execution
38
38
  */
39
39
  export type ToolResult = Record<string, unknown> | string | number | boolean | null;
40
+ /**
41
+ * Optional context passed to {@link LlmTool.run} by runners and brokers.
42
+ *
43
+ * The `signal` field is honoured by long-running tools that opt in to
44
+ * cancellation. Tools that ignore the context continue to work unchanged.
45
+ */
46
+ export interface ToolRunCtx {
47
+ /** AbortSignal that fires when the broker or runner cancels the batch. */
48
+ signal?: AbortSignal;
49
+ }
40
50
  /**
41
51
  * Interface for LLM tools
42
52
  */
43
53
  export interface LlmTool {
44
54
  /**
45
- * Execute the tool with the given arguments
55
+ * Execute the tool with the given arguments.
56
+ *
57
+ * The optional `ctx` parameter carries cancellation information. Tools may
58
+ * ignore it for back-compat; tools that perform long-running work should
59
+ * observe `ctx.signal` so that {@link ParallelToolRunner} or the
60
+ * realtime broker can hard-cancel them on interruption.
46
61
  */
47
- run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
62
+ run(args: ToolArgs, ctx?: ToolRunCtx): Promise<Result<ToolResult, Error>>;
48
63
  /**
49
64
  * Get the tool descriptor for LLM
50
65
  */
@@ -62,7 +77,7 @@ export interface LlmTool {
62
77
  * Abstract base class for tools
63
78
  */
64
79
  export declare abstract class BaseTool implements LlmTool {
65
- abstract run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
80
+ abstract run(args: ToolArgs, ctx?: ToolRunCtx): Promise<Result<ToolResult, Error>>;
66
81
  abstract descriptor(): ToolDescriptor;
67
82
  name(): string;
68
83
  matches(name: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/llm/tools/tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,Q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AAI,EAAE,KAAK,IAAI,CAAC;IAC9B,CAAC;CACF;AAXD,4BAWC"}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/llm/tools/tool.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAqFH;;GAEG;AACH,MAAsB,QAAQ;IAI5B,IAAI;QACF,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC;IAC9B,CAAC;CACF;AAXD,4BAWC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Realtime voice broker — sibling to {@link LlmBroker} for duplex
3
+ * voice + tool sessions.
4
+ */
5
+ import { Result } from '../error';
6
+ import { ToolRunner } from '../llm/tools';
7
+ import { TracerSystem } from '../tracer';
8
+ import { RealtimeVoiceConfig } from './config';
9
+ import { RealtimeVoiceGateway } from './gateway';
10
+ import { RealtimeSession } from './session';
11
+ /**
12
+ * Connect-time overrides for a single session. Anything omitted falls back
13
+ * to the broker-level config supplied at construction.
14
+ */
15
+ export type RealtimeSessionOverrides = Partial<RealtimeVoiceConfig>;
16
+ /**
17
+ * Long-lived broker that opens duplex realtime sessions against a gateway.
18
+ *
19
+ * The broker itself holds no session state — it is reusable across many
20
+ * concurrent sessions. The {@link RealtimeSession} returned by
21
+ * {@link connect} owns the socket lifetime.
22
+ */
23
+ export declare class RealtimeVoiceBroker {
24
+ private readonly model;
25
+ private readonly gateway;
26
+ private readonly config;
27
+ private readonly tracer?;
28
+ private readonly toolRunner;
29
+ constructor(model: string, gateway: RealtimeVoiceGateway, config?: RealtimeVoiceConfig, tracer?: TracerSystem | undefined, toolRunner?: ToolRunner);
30
+ /**
31
+ * Open a new realtime session.
32
+ *
33
+ * The session is fully initialised (initial `session.update` sent) before
34
+ * resolving so callers can immediately pipe audio or send text.
35
+ */
36
+ connect(overrides?: RealtimeSessionOverrides): Promise<Result<RealtimeSession, Error>>;
37
+ getModel(): string;
38
+ getGateway(): RealtimeVoiceGateway;
39
+ }
40
+ //# sourceMappingURL=broker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/realtime/broker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAW,MAAM,EAAQ,MAAM,UAAU,CAAC;AACjD,OAAO,EAAsB,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAJV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,mBAAwB,EAChC,MAAM,CAAC,EAAE,YAAY,YAAA,EACrB,UAAU,GAAE,UAAqC;IAGpE;;;;;OAKG;IACG,OAAO,CAAC,SAAS,GAAE,wBAA6B,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IAgChG,QAAQ,IAAI,MAAM;IAIlB,UAAU,IAAI,oBAAoB;CAGnC"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Realtime voice broker — sibling to {@link LlmBroker} for duplex
4
+ * voice + tool sessions.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.RealtimeVoiceBroker = void 0;
8
+ const crypto_1 = require("crypto");
9
+ const error_1 = require("../error");
10
+ const tools_1 = require("../llm/tools");
11
+ const session_1 = require("./session");
12
+ /**
13
+ * Long-lived broker that opens duplex realtime sessions against a gateway.
14
+ *
15
+ * The broker itself holds no session state — it is reusable across many
16
+ * concurrent sessions. The {@link RealtimeSession} returned by
17
+ * {@link connect} owns the socket lifetime.
18
+ */
19
+ class RealtimeVoiceBroker {
20
+ model;
21
+ gateway;
22
+ config;
23
+ tracer;
24
+ toolRunner;
25
+ constructor(model, gateway, config = {}, tracer, toolRunner = new tools_1.ParallelToolRunner()) {
26
+ this.model = model;
27
+ this.gateway = gateway;
28
+ this.config = config;
29
+ this.tracer = tracer;
30
+ this.toolRunner = toolRunner;
31
+ }
32
+ /**
33
+ * Open a new realtime session.
34
+ *
35
+ * The session is fully initialised (initial `session.update` sent) before
36
+ * resolving so callers can immediately pipe audio or send text.
37
+ */
38
+ async connect(overrides = {}) {
39
+ const merged = {
40
+ ...this.config,
41
+ ...overrides,
42
+ tools: overrides.tools ?? this.config.tools,
43
+ providerExtras: {
44
+ ...(this.config.providerExtras ?? {}),
45
+ ...(overrides.providerExtras ?? {}),
46
+ },
47
+ };
48
+ const correlationId = (0, crypto_1.randomUUID)();
49
+ const gatewayResult = await this.gateway.open(this.model, merged, correlationId);
50
+ if (!(0, error_1.isOk)(gatewayResult)) {
51
+ return (0, error_1.Err)(gatewayResult.error);
52
+ }
53
+ const session = new session_1.RealtimeSession(gatewayResult.value, {
54
+ config: merged,
55
+ toolRunner: this.toolRunner,
56
+ tracer: this.tracer,
57
+ correlationId,
58
+ });
59
+ const initResult = await session.initialise();
60
+ if (!(0, error_1.isOk)(initResult)) {
61
+ await session.close();
62
+ return (0, error_1.Err)(initResult.error);
63
+ }
64
+ return (0, error_1.Ok)(session);
65
+ }
66
+ getModel() {
67
+ return this.model;
68
+ }
69
+ getGateway() {
70
+ return this.gateway;
71
+ }
72
+ }
73
+ exports.RealtimeVoiceBroker = RealtimeVoiceBroker;
74
+ //# sourceMappingURL=broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/realtime/broker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAoC;AACpC,oCAAiD;AACjD,wCAA8D;AAI9D,uCAA4C;AAQ5C;;;;;;GAMG;AACH,MAAa,mBAAmB;IAEX;IACA;IACA;IACA;IACA;IALnB,YACmB,KAAa,EACb,OAA6B,EAC7B,SAA8B,EAAE,EAChC,MAAqB,EACrB,aAAyB,IAAI,0BAAkB,EAAE;QAJjD,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAsB;QAC7B,WAAM,GAAN,MAAM,CAA0B;QAChC,WAAM,GAAN,MAAM,CAAe;QACrB,eAAU,GAAV,UAAU,CAAuC;IACjE,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,YAAsC,EAAE;QACpD,MAAM,MAAM,GAAwB;YAClC,GAAG,IAAI,CAAC,MAAM;YACd,GAAG,SAAS;YACZ,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK;YAC3C,cAAc,EAAE;gBACd,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;gBACrC,GAAG,CAAC,SAAS,CAAC,cAAc,IAAI,EAAE,CAAC;aACpC;SACF,CAAC;QACF,MAAM,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAC;QAEnC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;QACjF,IAAI,CAAC,IAAA,YAAI,EAAC,aAAa,CAAC,EAAE,CAAC;YACzB,OAAO,IAAA,WAAG,EAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,yBAAe,CAAC,aAAa,CAAC,KAAK,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,aAAa;SACd,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAA,YAAI,EAAC,UAAU,CAAC,EAAE,CAAC;YACtB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,IAAA,WAAG,EAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,IAAA,UAAE,EAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAtDD,kDAsDC"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Configuration for the realtime voice subsystem.
3
+ *
4
+ * Mirrors the slice of OpenAI's Realtime session config that ports cleanly
5
+ * to other Mojentic implementations. Provider-specific knobs live in
6
+ * `providerExtras`.
7
+ */
8
+ import { LlmTool } from '../llm/tools';
9
+ /**
10
+ * Built-in voice options OpenAI's Realtime API exposes.
11
+ *
12
+ * Accepts arbitrary strings to allow new voices without a library update.
13
+ */
14
+ export type RealtimeVoice = 'alloy' | 'verse' | 'shimmer' | 'echo' | 'ballad' | 'sage' | string;
15
+ /**
16
+ * Audio modality selector.
17
+ */
18
+ export type RealtimeModality = 'audio' | 'text';
19
+ /**
20
+ * Audio frame format OpenAI accepts on the wire.
21
+ *
22
+ * `pcm16` is the default — 16-bit signed little-endian PCM, mono, 24 kHz.
23
+ */
24
+ export type RealtimeAudioFormat = 'pcm16' | 'g711_ulaw' | 'g711_alaw';
25
+ /**
26
+ * Tunable parameters for server-side voice-activity detection.
27
+ *
28
+ * Bump `threshold` up (e.g. 0.7–0.9) to make the VAD less sensitive to
29
+ * background noise. Set `interruptResponse: false` to disable barge-in
30
+ * entirely so the assistant's reply can't be cancelled mid-sentence by a
31
+ * cough or keyboard click.
32
+ */
33
+ export interface ServerVadConfig {
34
+ type?: 'server_vad';
35
+ /** Activation threshold (0.0–1.0). Lower fires on quieter speech. Default ≈ 0.5. */
36
+ threshold?: number;
37
+ /** Padding (ms) added to the start of a detected utterance. */
38
+ prefixPaddingMs?: number;
39
+ /** Silence (ms) before declaring the user is done speaking. */
40
+ silenceDurationMs?: number;
41
+ /** Whether VAD should auto-fire a `response.create` after the user stops. Default true. */
42
+ createResponse?: boolean;
43
+ /**
44
+ * Whether speech detected during an in-flight assistant response should
45
+ * cancel it (barge-in). Default true. Set false to mute false-positive
46
+ * interruptions from background noise.
47
+ */
48
+ interruptResponse?: boolean;
49
+ /** Max silence (ms) before the server idles the session. */
50
+ idleTimeoutMs?: number;
51
+ }
52
+ /**
53
+ * Semantic VAD mode — uses an LLM-side classifier to decide whether
54
+ * detected audio is intentional speech vs background noise. More robust
55
+ * than energy-threshold VAD in noisy environments.
56
+ */
57
+ export interface SemanticVadConfig {
58
+ type: 'semantic_vad';
59
+ /** Sensitivity of the classifier. `low` = least likely to fire. */
60
+ eagerness?: 'low' | 'medium' | 'high' | 'auto';
61
+ createResponse?: boolean;
62
+ interruptResponse?: boolean;
63
+ }
64
+ /**
65
+ * Turn-detection strategy.
66
+ *
67
+ * - `server_vad` — server decides when the user stopped talking and auto-fires
68
+ * a response. Natural phone-call mode. Energy-threshold-based.
69
+ * - `none` — client decides when to commit the buffer and request a response.
70
+ * Useful for push-to-talk and tests.
71
+ * - `semantic_vad` — LLM-classifier-driven VAD. Best for noisy environments.
72
+ * - A {@link ServerVadConfig} or {@link SemanticVadConfig} object — tune
73
+ * thresholds and behaviour.
74
+ */
75
+ export type TurnDetectionMode = 'server_vad' | 'semantic_vad' | 'none' | ServerVadConfig | SemanticVadConfig;
76
+ /**
77
+ * Policy for handling tool outputs from a cancelled response.
78
+ *
79
+ * - `drop` (default) — don't submit any outputs from the cancelled batch.
80
+ * Stale answers don't pollute context.
81
+ * - `submit-completed-only` — submit outputs for tools that finished before
82
+ * the abort signal landed; drop in-flight ones.
83
+ * - `submit` — submit all outputs that eventually arrive, even after the
84
+ * model started a new response.
85
+ */
86
+ export type InterruptOutputPolicy = 'drop' | 'submit' | 'submit-completed-only';
87
+ /**
88
+ * Choice strategy for tools in the session.
89
+ */
90
+ export type RealtimeToolChoice = 'auto' | 'none' | 'required' | {
91
+ name: string;
92
+ };
93
+ /**
94
+ * Vendor-neutral configuration for a realtime voice session.
95
+ *
96
+ * The library forwards a curated subset to the active gateway and translates
97
+ * vendor-specific shapes at the boundary.
98
+ */
99
+ export interface RealtimeVoiceConfig {
100
+ /** System-level instructions injected into every assistant turn. */
101
+ instructions?: string;
102
+ /** Voice id to render assistant audio with. */
103
+ voice?: RealtimeVoice;
104
+ /** Active modalities. Default `['audio', 'text']`. */
105
+ modalities?: RealtimeModality[];
106
+ /** Encoding of audio frames the client sends. Default `pcm16`. */
107
+ inputAudioFormat?: RealtimeAudioFormat;
108
+ /** Encoding of audio frames the server returns. Default `pcm16`. */
109
+ outputAudioFormat?: RealtimeAudioFormat;
110
+ /** Turn-detection strategy. Default `server_vad`. */
111
+ turnDetection?: TurnDetectionMode;
112
+ /** Whisper transcription config for user audio. Pass `false` to disable. */
113
+ inputAudioTranscription?: {
114
+ model: 'whisper-1';
115
+ } | false;
116
+ /** Tools available to the model in this session. */
117
+ tools?: LlmTool[];
118
+ /** Tool-selection strategy. Default `auto`. */
119
+ toolChoice?: RealtimeToolChoice;
120
+ /** Sampling temperature. */
121
+ temperature?: number;
122
+ /** Cap on output tokens per response. */
123
+ maxResponseOutputTokens?: number;
124
+ /** How to treat tool outputs from interrupted/cancelled responses. */
125
+ onInterrupt?: InterruptOutputPolicy;
126
+ /** Provider-specific escape hatch — passed through verbatim to the gateway. */
127
+ providerExtras?: Record<string, unknown>;
128
+ }
129
+ /**
130
+ * Default config used when a field is omitted. Surfaced so consumers can
131
+ * read effective values without re-implementing the merge themselves.
132
+ */
133
+ export declare const REALTIME_DEFAULTS: Required<Pick<RealtimeVoiceConfig, 'modalities' | 'inputAudioFormat' | 'outputAudioFormat' | 'turnDetection' | 'toolChoice' | 'onInterrupt'>>;
134
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/realtime/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhG;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAEtE;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2FAA2F;IAC3F,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,mEAAmE;IACnE,SAAS,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,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CACtC,IAAI,CACF,mBAAmB,EACjB,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,eAAe,GACf,YAAY,GACZ,aAAa,CAChB,CAQF,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration for the realtime voice subsystem.
4
+ *
5
+ * Mirrors the slice of OpenAI's Realtime session config that ports cleanly
6
+ * to other Mojentic implementations. Provider-specific knobs live in
7
+ * `providerExtras`.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.REALTIME_DEFAULTS = void 0;
11
+ /**
12
+ * Default config used when a field is omitted. Surfaced so consumers can
13
+ * read effective values without re-implementing the merge themselves.
14
+ */
15
+ exports.REALTIME_DEFAULTS = {
16
+ modalities: ['audio', 'text'],
17
+ inputAudioFormat: 'pcm16',
18
+ outputAudioFormat: 'pcm16',
19
+ turnDetection: 'server_vad',
20
+ toolChoice: 'auto',
21
+ onInterrupt: 'drop',
22
+ };
23
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/realtime/config.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAsIH;;;GAGG;AACU,QAAA,iBAAiB,GAU1B;IACF,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,OAAO;IACzB,iBAAiB,EAAE,OAAO;IAC1B,aAAa,EAAE,YAAY;IAC3B,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,MAAM;CACpB,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Vendor-neutral event union for the realtime subsystem.
3
+ *
4
+ * Consumers subscribe to this union rather than raw OpenAI events so the
5
+ * same observer code ports cleanly to other realtime providers and other
6
+ * Mojentic implementations (Python, Elixir, Rust).
7
+ */
8
+ import { ToolArgs, ToolResult } from '../llm/tools';
9
+ import { RealtimeVoiceConfig } from './config';
10
+ /**
11
+ * Token usage reported when a response turn completes.
12
+ */
13
+ export interface TokenUsage {
14
+ promptTokens?: number;
15
+ completionTokens?: number;
16
+ totalTokens?: number;
17
+ /** Provider-specific breakdown (e.g. audio vs text tokens). */
18
+ extras?: Record<string, unknown>;
19
+ }
20
+ /**
21
+ * Conversation item in a realtime session.
22
+ *
23
+ * Realtime sessions don't map cleanly to chat-completion `LlmMessage`s
24
+ * because they carry audio, multi-modal content, and tool-call lifecycle
25
+ * separate from any single message. We carry a small dedicated shape so
26
+ * `LlmMessage` doesn't get bent out of shape.
27
+ */
28
+ export interface RealtimeItem {
29
+ id: string;
30
+ /** Item kind — message, function-call, or function-call output. */
31
+ type: 'message' | 'function_call' | 'function_call_output';
32
+ /** Role for message items. */
33
+ role?: 'system' | 'user' | 'assistant';
34
+ /** Text content (assembled from streamed deltas). */
35
+ text?: string;
36
+ /** Transcript content (assembled from streamed audio deltas). */
37
+ transcript?: string;
38
+ /** Function name for function_call / function_call_output items. */
39
+ name?: string;
40
+ /** Parsed JSON arguments for function_call items. */
41
+ args?: ToolArgs;
42
+ /** Tool execution result for function_call_output items. */
43
+ output?: ToolResult;
44
+ /** Pair function_call → function_call_output. */
45
+ callId?: string;
46
+ }
47
+ /**
48
+ * Vendor-neutral event types emitted by {@link RealtimeSession}.
49
+ */
50
+ export type RealtimeEvent = {
51
+ kind: 'session_opened';
52
+ sessionId: string;
53
+ } | {
54
+ kind: 'session_updated';
55
+ config: Partial<RealtimeVoiceConfig>;
56
+ } | {
57
+ kind: 'session_closed';
58
+ reason: 'client' | 'server' | 'error';
59
+ } | {
60
+ kind: 'user_speech_started';
61
+ atMs: number;
62
+ } | {
63
+ kind: 'user_speech_stopped';
64
+ atMs: number;
65
+ } | {
66
+ kind: 'user_transcript_delta';
67
+ itemId: string;
68
+ delta: string;
69
+ } | {
70
+ kind: 'user_transcript';
71
+ itemId: string;
72
+ text: string;
73
+ } | {
74
+ kind: 'assistant_turn_started';
75
+ turnId: string;
76
+ } | {
77
+ kind: 'assistant_text_delta';
78
+ turnId: string;
79
+ delta: string;
80
+ } | {
81
+ kind: 'assistant_text';
82
+ turnId: string;
83
+ text: string;
84
+ } | {
85
+ kind: 'assistant_transcript_delta';
86
+ turnId: string;
87
+ delta: string;
88
+ } | {
89
+ kind: 'assistant_transcript';
90
+ turnId: string;
91
+ text: string;
92
+ } | {
93
+ kind: 'assistant_audio_delta';
94
+ turnId: string;
95
+ pcm: Int16Array;
96
+ } | {
97
+ kind: 'assistant_turn_completed';
98
+ turnId: string;
99
+ usage?: TokenUsage;
100
+ } | {
101
+ kind: 'tool_call_started';
102
+ turnId: string;
103
+ callId: string;
104
+ name: string;
105
+ } | {
106
+ kind: 'tool_call_args_delta';
107
+ callId: string;
108
+ delta: string;
109
+ } | {
110
+ kind: 'tool_call_dispatched';
111
+ callId: string;
112
+ name: string;
113
+ args: ToolArgs;
114
+ } | {
115
+ kind: 'tool_call_completed';
116
+ callId: string;
117
+ name: string;
118
+ result: ToolResult;
119
+ } | {
120
+ kind: 'tool_call_failed';
121
+ callId: string;
122
+ name: string;
123
+ error: Error;
124
+ } | {
125
+ kind: 'tool_batch_submitted';
126
+ turnId: string;
127
+ callIds: string[];
128
+ } | {
129
+ kind: 'interrupted';
130
+ turnId: string;
131
+ reason: 'barge_in' | 'manual' | 'error';
132
+ } | {
133
+ kind: 'rate_limited';
134
+ resetMs: number;
135
+ details: Record<string, unknown>;
136
+ } | {
137
+ kind: 'error';
138
+ error: Error;
139
+ recoverable: boolean;
140
+ };
141
+ /**
142
+ * Narrow helper for discriminating events by `kind` in switch statements
143
+ * without losing exhaustiveness checking.
144
+ */
145
+ export type RealtimeEventKind = RealtimeEvent['kind'];
146
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/realtime/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sB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/D;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAChB,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;CACpB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,GACD;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAGnE;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;CACzC,GACD;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GACD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * Vendor-neutral event union for the realtime subsystem.
4
+ *
5
+ * Consumers subscribe to this union rather than raw OpenAI events so the
6
+ * same observer code ports cleanly to other realtime providers and other
7
+ * Mojentic implementations (Python, Elixir, Rust).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/realtime/events.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}