@guava-ai/guava-sdk 0.22.0 → 0.24.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 (57) hide show
  1. package/dist/examples/help-desk.js +22 -8
  2. package/dist/examples/help-desk.js.map +1 -1
  3. package/dist/examples/property-insurance.js +14 -3
  4. package/dist/examples/property-insurance.js.map +1 -1
  5. package/dist/examples/restaurant-waitlist.js +9 -1
  6. package/dist/examples/restaurant-waitlist.js.map +1 -1
  7. package/dist/examples/scheduling-outbound.js +2 -4
  8. package/dist/examples/scheduling-outbound.js.map +1 -1
  9. package/dist/src/action-item.d.ts +4 -4
  10. package/dist/src/action-item.js +1 -1
  11. package/dist/src/action-item.js.map +1 -1
  12. package/dist/src/agent.d.ts +21 -7
  13. package/dist/src/agent.js +275 -123
  14. package/dist/src/agent.js.map +1 -1
  15. package/dist/src/call.d.ts +9 -1
  16. package/dist/src/call.js +24 -1
  17. package/dist/src/call.js.map +1 -1
  18. package/dist/src/commands.d.ts +37 -9
  19. package/dist/src/commands.js +13 -3
  20. package/dist/src/commands.js.map +1 -1
  21. package/dist/src/events.d.ts +31 -1
  22. package/dist/src/events.js +11 -2
  23. package/dist/src/events.js.map +1 -1
  24. package/dist/src/health.d.ts +35 -0
  25. package/dist/src/health.js +99 -0
  26. package/dist/src/health.js.map +1 -0
  27. package/dist/src/helpers/index.d.ts +1 -0
  28. package/dist/src/helpers/index.js +9 -0
  29. package/dist/src/helpers/index.js.map +1 -0
  30. package/dist/src/helpers/llm.d.ts +33 -1
  31. package/dist/src/helpers/llm.js +220 -0
  32. package/dist/src/helpers/llm.js.map +1 -1
  33. package/dist/src/helpers/server-rag.d.ts +25 -0
  34. package/dist/src/helpers/server-rag.js +119 -0
  35. package/dist/src/helpers/server-rag.js.map +1 -0
  36. package/dist/src/socket/protocol.d.ts +4 -4
  37. package/dist/src/testing/mocks.d.ts +6 -0
  38. package/dist/src/testing/mocks.js +12 -0
  39. package/dist/src/testing/mocks.js.map +1 -1
  40. package/dist/src/version.d.ts +1 -1
  41. package/dist/src/version.js +1 -1
  42. package/examples/help-desk.ts +21 -12
  43. package/examples/property-insurance.ts +15 -3
  44. package/examples/restaurant-waitlist.ts +10 -1
  45. package/examples/scheduling-outbound.ts +2 -4
  46. package/package.json +5 -1
  47. package/src/action-item.ts +1 -1
  48. package/src/agent.ts +271 -129
  49. package/src/call.ts +37 -1
  50. package/src/commands.ts +16 -2
  51. package/src/events.ts +12 -1
  52. package/src/health.ts +120 -0
  53. package/src/helpers/index.ts +2 -0
  54. package/src/helpers/llm.ts +178 -1
  55. package/src/helpers/server-rag.ts +132 -0
  56. package/src/testing/mocks.ts +17 -0
  57. package/src/version.ts +1 -1
@@ -0,0 +1,35 @@
1
+ import { type Logger } from "./logging.ts";
2
+ export type HealthState = "starting" | "live" | "stopped";
3
+ export declare class HealthContext {
4
+ private _state;
5
+ setState(newState: HealthState): void;
6
+ ready(): void;
7
+ stopped(): void;
8
+ isLive(): boolean;
9
+ }
10
+ export declare class MultiHealthContext {
11
+ private _ctxs;
12
+ createCtx(): HealthContext;
13
+ isLive(): boolean;
14
+ }
15
+ export interface HealthServerOptions {
16
+ host?: string;
17
+ port?: number;
18
+ logger?: Logger;
19
+ }
20
+ export declare class HealthServer implements AsyncDisposable {
21
+ private readonly _server;
22
+ private readonly _logger;
23
+ private _stopping;
24
+ private constructor();
25
+ static start(healthCtx: HealthContext | MultiHealthContext, options?: HealthServerOptions): Promise<HealthServer>;
26
+ stop(): Promise<void>;
27
+ [Symbol.asyncDispose](): Promise<void>;
28
+ }
29
+ /**
30
+ * Returns an AsyncDisposable that, when the GUAVA_HEALTH_SERVER env var is
31
+ * truthy ("yes", "true", "on"), starts an HTTP health check server exposing
32
+ * `/live` on port 4828. Otherwise returns a no-op disposable. Intended for use
33
+ * with `await using`.
34
+ */
35
+ export declare function getHealthServer(healthCtx: HealthContext | MultiHealthContext): Promise<AsyncDisposable>;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HealthServer = exports.MultiHealthContext = exports.HealthContext = void 0;
4
+ exports.getHealthServer = getHealthServer;
5
+ const node_http_1 = require("node:http");
6
+ const logging_ts_1 = require("./logging.js");
7
+ class HealthContext {
8
+ _state = "starting";
9
+ setState(newState) {
10
+ this._state = newState;
11
+ }
12
+ ready() {
13
+ this.setState("live");
14
+ }
15
+ stopped() {
16
+ this.setState("stopped");
17
+ }
18
+ isLive() {
19
+ return this._state === "live";
20
+ }
21
+ }
22
+ exports.HealthContext = HealthContext;
23
+ class MultiHealthContext {
24
+ _ctxs = [];
25
+ createCtx() {
26
+ const ctx = new HealthContext();
27
+ this._ctxs.push(ctx);
28
+ return ctx;
29
+ }
30
+ isLive() {
31
+ return this._ctxs.length > 0 && this._ctxs.every((ctx) => ctx.isLive());
32
+ }
33
+ }
34
+ exports.MultiHealthContext = MultiHealthContext;
35
+ class HealthServer {
36
+ _server;
37
+ _logger;
38
+ _stopping = null;
39
+ constructor(server, logger) {
40
+ this._server = server;
41
+ this._logger = logger;
42
+ }
43
+ static async start(healthCtx, options = {}) {
44
+ const host = options.host ?? "0.0.0.0";
45
+ const port = options.port ?? 4828;
46
+ const logger = options.logger ?? (0, logging_ts_1.getDefaultLogger)();
47
+ const server = (0, node_http_1.createServer)((req, res) => {
48
+ if (req.method === "GET" && req.url === "/live") {
49
+ res.statusCode = healthCtx.isLive() ? 200 : 503;
50
+ }
51
+ else {
52
+ res.statusCode = 404;
53
+ }
54
+ res.end();
55
+ });
56
+ await new Promise((resolve, reject) => {
57
+ server.once("error", reject);
58
+ server.listen(port, host, () => {
59
+ server.off("error", reject);
60
+ resolve();
61
+ });
62
+ });
63
+ logger.info("Health check server listening on http://%s:%d/live", host, port);
64
+ return new HealthServer(server, logger);
65
+ }
66
+ stop() {
67
+ if (this._stopping)
68
+ return this._stopping;
69
+ this._logger.info("Health check server shutting down.");
70
+ this._stopping = new Promise((resolve, reject) => {
71
+ this._server.closeAllConnections();
72
+ this._server.close((err) => (err ? reject(err) : resolve()));
73
+ });
74
+ return this._stopping;
75
+ }
76
+ async [Symbol.asyncDispose]() {
77
+ await this.stop();
78
+ }
79
+ }
80
+ exports.HealthServer = HealthServer;
81
+ const NOOP_DISPOSABLE = {
82
+ async [Symbol.asyncDispose]() { },
83
+ };
84
+ function isEnabled() {
85
+ const value = (process.env.GUAVA_HEALTH_SERVER ?? "false").toLowerCase().trim();
86
+ return value === "yes" || value === "true" || value === "on";
87
+ }
88
+ /**
89
+ * Returns an AsyncDisposable that, when the GUAVA_HEALTH_SERVER env var is
90
+ * truthy ("yes", "true", "on"), starts an HTTP health check server exposing
91
+ * `/live` on port 4828. Otherwise returns a no-op disposable. Intended for use
92
+ * with `await using`.
93
+ */
94
+ async function getHealthServer(healthCtx) {
95
+ if (!isEnabled())
96
+ return NOOP_DISPOSABLE;
97
+ return HealthServer.start(healthCtx);
98
+ }
99
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":";;;AAkHA,0CAKC;AAvHD,yCAAsD;AACtD,6CAA6D;AAI7D,MAAa,aAAa;IAChB,MAAM,GAAgB,UAAU,CAAC;IAEzC,QAAQ,CAAC,QAAqB;QAC5B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC;IAChC,CAAC;CACF;AAlBD,sCAkBC;AAED,MAAa,kBAAkB;IACrB,KAAK,GAAoB,EAAE,CAAC;IAEpC,SAAS;QACP,MAAM,GAAG,GAAG,IAAI,aAAa,EAAE,CAAC;QAChC,IAAI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AAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IAChF,OAAO,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,IAAI,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,SAA6C;IAE7C,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO,eAAe,CAAC;IACzC,OAAO,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1 @@
1
+ export { DatetimeFilter, DocumentQA, IntentRecognizer } from "./llm.ts";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntentRecognizer = exports.DocumentQA = exports.DatetimeFilter = void 0;
4
+ /* This file must not include the OpenAI helpers. */
5
+ var llm_ts_1 = require("./llm.js");
6
+ Object.defineProperty(exports, "DatetimeFilter", { enumerable: true, get: function () { return llm_ts_1.DatetimeFilter; } });
7
+ Object.defineProperty(exports, "DocumentQA", { enumerable: true, get: function () { return llm_ts_1.DocumentQA; } });
8
+ Object.defineProperty(exports, "IntentRecognizer", { enumerable: true, get: function () { return llm_ts_1.IntentRecognizer; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACpD,mCAAwE;AAA/D,wGAAA,cAAc,OAAA;AAAE,oGAAA,UAAU,OAAA;AAAE,0GAAA,gBAAgB,OAAA"}
@@ -1,2 +1,34 @@
1
- import type { Client } from "../client.ts";
1
+ import type { SuggestedAction } from "../agent.ts";
2
+ import { Client } from "../client.ts";
2
3
  export declare function _generate(client: Client, prompt: string, jsonSchema?: object): Promise<string>;
4
+ export declare class DocumentQA {
5
+ private readonly _rag;
6
+ private readonly _instructions;
7
+ private readonly _initialized;
8
+ constructor({ documents, ids, instructions, namespace, }?: {
9
+ documents?: string | string[];
10
+ ids?: string[];
11
+ instructions?: string;
12
+ namespace?: string;
13
+ });
14
+ upsertDocument(key: string, text: string): Promise<void>;
15
+ addDocument(text: string): Promise<void>;
16
+ deleteDocument(key: string): Promise<void>;
17
+ clear(): Promise<void>;
18
+ ask(question: string): Promise<string>;
19
+ }
20
+ export declare class DatetimeFilter {
21
+ private readonly _client;
22
+ private readonly _slotsStr;
23
+ constructor(sourceList: string[]);
24
+ filter(query: string, { maxResults }?: {
25
+ maxResults?: number;
26
+ }): Promise<[string[], string[]]>;
27
+ }
28
+ export declare class IntentRecognizer {
29
+ private readonly _client;
30
+ private readonly _intentChoices;
31
+ private readonly _schema;
32
+ constructor(intentChoices: string[] | Record<string, string>);
33
+ classify(intent: string): Promise<SuggestedAction[] | null>;
34
+ }
@@ -1,7 +1,45 @@
1
1
  "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.IntentRecognizer = exports.DatetimeFilter = exports.DocumentQA = void 0;
3
38
  exports._generate = _generate;
39
+ const client_ts_1 = require("../client.js");
40
+ const telemetry_ts_1 = require("../telemetry.js");
4
41
  const utils_ts_1 = require("../utils.js");
42
+ const server_rag_ts_1 = require("./server-rag.js");
5
43
  async function _generate(client, prompt, jsonSchema) {
6
44
  const url = new URL("v1/llm/generate", client.getHttpBase());
7
45
  const body = { prompt };
@@ -11,7 +49,189 @@ async function _generate(client, prompt, jsonSchema) {
11
49
  method: "POST",
12
50
  headers: { ...(await client.headers()), "Content-Type": "application/json" },
13
51
  body: JSON.stringify(body),
52
+ signal: AbortSignal.timeout(60_000),
14
53
  });
15
54
  return (await response.json()).text;
16
55
  }
56
+ let DocumentQA = (() => {
57
+ let _classDecorators = [telemetry_ts_1.telemetryClient.trackClass()];
58
+ let _classDescriptor;
59
+ let _classExtraInitializers = [];
60
+ let _classThis;
61
+ var DocumentQA = class {
62
+ static { _classThis = this; }
63
+ static {
64
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
65
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
66
+ DocumentQA = _classThis = _classDescriptor.value;
67
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
68
+ __runInitializers(_classThis, _classExtraInitializers);
69
+ }
70
+ _rag;
71
+ _instructions;
72
+ _initialized;
73
+ constructor({ documents, ids, instructions, namespace, } = {}) {
74
+ this._rag = new server_rag_ts_1.ServerRAG(new client_ts_1.Client(), { namespace });
75
+ this._instructions = instructions;
76
+ if (documents !== undefined) {
77
+ const docs = typeof documents === "string" ? [documents] : documents;
78
+ this._initialized = this._rag.reconcile(docs, ids);
79
+ }
80
+ else {
81
+ this._initialized = Promise.resolve();
82
+ }
83
+ }
84
+ async upsertDocument(key, text) {
85
+ await this._initialized;
86
+ await this._rag.upsertDocument(key, text);
87
+ }
88
+ async addDocument(text) {
89
+ await this._initialized;
90
+ await this._rag.addDocument(text);
91
+ }
92
+ async deleteDocument(key) {
93
+ await this._initialized;
94
+ await this._rag.removeDocument(key);
95
+ }
96
+ async clear() {
97
+ await this._initialized;
98
+ await this._rag.clear();
99
+ }
100
+ async ask(question) {
101
+ await this._initialized;
102
+ const trackedKeys = this._rag.trackedKeys;
103
+ return this._rag.ask(question, {
104
+ documentKeys: trackedKeys.size > 0 ? [...trackedKeys] : undefined,
105
+ instructions: this._instructions,
106
+ });
107
+ }
108
+ };
109
+ return DocumentQA = _classThis;
110
+ })();
111
+ exports.DocumentQA = DocumentQA;
112
+ const _filterSchema = {
113
+ type: "object",
114
+ properties: {
115
+ matching_appointments: { type: "array", items: { type: "string" } },
116
+ other_appointments: { type: "array", items: { type: "string" } },
117
+ },
118
+ required: ["matching_appointments", "other_appointments"],
119
+ additionalProperties: false,
120
+ };
121
+ let DatetimeFilter = (() => {
122
+ let _classDecorators = [telemetry_ts_1.telemetryClient.trackClass()];
123
+ let _classDescriptor;
124
+ let _classExtraInitializers = [];
125
+ let _classThis;
126
+ var DatetimeFilter = class {
127
+ static { _classThis = this; }
128
+ static {
129
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
130
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
131
+ DatetimeFilter = _classThis = _classDescriptor.value;
132
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
133
+ __runInitializers(_classThis, _classExtraInitializers);
134
+ }
135
+ _client;
136
+ _slotsStr;
137
+ constructor(sourceList) {
138
+ this._client = new client_ts_1.Client();
139
+ this._slotsStr = sourceList.join("\n");
140
+ }
141
+ async filter(query, { maxResults = 5 } = {}) {
142
+ const today = new Date().toLocaleDateString("en-US", {
143
+ month: "long",
144
+ day: "numeric",
145
+ year: "numeric",
146
+ });
147
+ const prompt = `Return datetime slots from the list that match the query.
148
+ If none match, return close alternatives in other_appointments instead.
149
+ Never return datetimes that are not in the list.
150
+
151
+ Query: <query>${query}</query>
152
+ Today's Date: ${today}
153
+ Available slots:
154
+ ${this._slotsStr}
155
+
156
+ Return at most ${maxResults} items per list.`;
157
+ const text = await _generate(this._client, prompt, _filterSchema);
158
+ const result = JSON.parse(text);
159
+ return [
160
+ result.matching_appointments.slice(0, maxResults),
161
+ result.other_appointments.slice(0, maxResults),
162
+ ];
163
+ }
164
+ };
165
+ return DatetimeFilter = _classThis;
166
+ })();
167
+ exports.DatetimeFilter = DatetimeFilter;
168
+ let IntentRecognizer = (() => {
169
+ let _classDecorators = [telemetry_ts_1.telemetryClient.trackClass()];
170
+ let _classDescriptor;
171
+ let _classExtraInitializers = [];
172
+ let _classThis;
173
+ var IntentRecognizer = class {
174
+ static { _classThis = this; }
175
+ static {
176
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
177
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
178
+ IntentRecognizer = _classThis = _classDescriptor.value;
179
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
180
+ __runInitializers(_classThis, _classExtraInitializers);
181
+ }
182
+ _client;
183
+ _intentChoices;
184
+ _schema;
185
+ constructor(intentChoices) {
186
+ this._client = new client_ts_1.Client();
187
+ this._intentChoices = intentChoices;
188
+ const choiceList = Array.isArray(intentChoices) ? intentChoices : Object.keys(intentChoices);
189
+ this._schema = {
190
+ type: "object",
191
+ title: "ChoiceModel",
192
+ properties: {
193
+ possible_matches: {
194
+ type: "array",
195
+ items: { type: "string", enum: choiceList },
196
+ description: "Choices that could match the caller's intent, ordered by likelihood. Include all plausible matches.",
197
+ },
198
+ },
199
+ required: ["possible_matches"],
200
+ additionalProperties: false,
201
+ };
202
+ }
203
+ async classify(intent) {
204
+ const choiceList = Array.isArray(this._intentChoices)
205
+ ? this._intentChoices
206
+ : Object.keys(this._intentChoices);
207
+ let prompt = `Classify the intent below into the most appropriate choice(s) from the list.
208
+
209
+ Intent: <intent>${intent}</intent>
210
+ Available Choices: ${JSON.stringify(choiceList)}
211
+
212
+ Rules:
213
+ - Default to returning a single choice — the one that best matches the intent.
214
+ - Only return additional choices when the intent is genuinely ambiguous: a reasonable person reading it would be unable to decide which category it belongs to. Thematic overlap or partial relevance is NOT enough — do not include weakly or tangentially related choices.
215
+ - Order matches by likelihood (most likely first).
216
+ - If no choice plausibly matches, return an empty list.`;
217
+ if (!Array.isArray(this._intentChoices)) {
218
+ const descriptionString = Object.entries(this._intentChoices)
219
+ .map(([key, val]) => `${key}: ${val}`)
220
+ .join("\n ");
221
+ prompt += `\n\nDetailed descriptions of each choice:\n ${descriptionString}`;
222
+ }
223
+ const text = await _generate(this._client, prompt, this._schema);
224
+ const keys = JSON.parse(text).possible_matches;
225
+ if (!keys.length)
226
+ return null;
227
+ if (!Array.isArray(this._intentChoices)) {
228
+ const choices = this._intentChoices;
229
+ return keys.map((k) => ({ key: k, description: choices[k] }));
230
+ }
231
+ return keys.map((k) => ({ key: k }));
232
+ }
233
+ };
234
+ return IntentRecognizer = _classThis;
235
+ })();
236
+ exports.IntentRecognizer = IntentRecognizer;
17
237
  //# sourceMappingURL=llm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"llm.js","sourceRoot":"","sources":["../../../src/helpers/llm.ts"],"names":[],"mappings":";;AAGA,8BAgBC;AAlBD,0CAA2C;AAEpC,KAAK,UAAU,SAAS,CAC7B,MAAc,EACd,MAAc,EACd,UAAmB;IAEnB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7D,MAAM,IAAI,GAA4B,EAAE,MAAM,EAAE,CAAC;IACjD,IAAI,UAAU,KAAK,SAAS;QAAE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAE5D,MAAM,QAAQ,GAAG,MAAM,IAAA,uBAAY,EAAC,GAAG,EAAE;QACvC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC5E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;IAEH,OAAQ,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAsB,CAAC,IAAI,CAAC;AAC5D,CAAC"}
1
+ {"version":3,"file":"llm.js","sourceRoot":"","sources":["../../../src/helpers/llm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,8BAiBC;AAtBD,4CAAsC;AACtC,kDAAkD;AAClD,0CAA2C;AAC3C,mDAA4C;AAErC,KAAK,UAAU,SAAS,CAC7B,MAAc,EACd,MAAc,EACd,UAAmB;IAEnB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,CA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AAE,CAAC,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC;qBACrC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAChB,MAAM,IAAI,gDAAgD,iBAAiB,EAAE,CAAC;YAChF,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACjE,MAAM,IAAI,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAoC,CAAC,gBAAgB,CAAC;YAEnF,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAE9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;gBACxC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC;gBACpC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACvC,CAAC;;;;AA1DU,4CAAgB"}
@@ -0,0 +1,25 @@
1
+ import type { Client } from "../client.ts";
2
+ export declare function _contentKey(text: string): string;
3
+ export declare function _prefixedKey(namespace: string | undefined, key: string): string;
4
+ export declare class ServerRAG {
5
+ private readonly _client;
6
+ private readonly _namespace;
7
+ readonly trackedKeys: Set<string>;
8
+ constructor(client: Client, { namespace }?: {
9
+ namespace?: string;
10
+ });
11
+ uploadDocument(key: string, text: string): Promise<void>;
12
+ deleteDocument(key: string): Promise<void>;
13
+ listDocuments(): Promise<{
14
+ key: string;
15
+ }[]>;
16
+ ask(question: string, { documentKeys, instructions }?: {
17
+ documentKeys?: string[];
18
+ instructions?: string;
19
+ }): Promise<string>;
20
+ reconcile(documents: string[], ids?: string[]): Promise<void>;
21
+ upsertDocument(key: string, text: string): Promise<void>;
22
+ addDocument(text: string): Promise<void>;
23
+ removeDocument(key: string): Promise<void>;
24
+ clear(): Promise<void>;
25
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerRAG = void 0;
4
+ exports._contentKey = _contentKey;
5
+ exports._prefixedKey = _prefixedKey;
6
+ const node_crypto_1 = require("node:crypto");
7
+ const utils_ts_1 = require("../utils.js");
8
+ function _contentKey(text) {
9
+ return (0, node_crypto_1.createHash)("sha256").update(text).digest("hex").slice(0, 16);
10
+ }
11
+ function _prefixedKey(namespace, key) {
12
+ return namespace ? `${namespace}.${key}` : key;
13
+ }
14
+ class ServerRAG {
15
+ _client;
16
+ _namespace;
17
+ trackedKeys = new Set();
18
+ constructor(client, { namespace } = {}) {
19
+ this._client = client;
20
+ this._namespace = namespace;
21
+ }
22
+ async uploadDocument(key, text) {
23
+ const url = new URL("v1/rag/documents", this._client.getHttpBase());
24
+ await (0, utils_ts_1.fetchOrThrow)(url, {
25
+ method: "POST",
26
+ headers: { ...(await this._client.headers()), "Content-Type": "application/json" },
27
+ body: JSON.stringify({ key, text }),
28
+ signal: AbortSignal.timeout(60_000),
29
+ });
30
+ }
31
+ async deleteDocument(key) {
32
+ const url = new URL(`v1/rag/documents/${key}`, this._client.getHttpBase());
33
+ await (0, utils_ts_1.fetchOrThrow)(url, {
34
+ method: "DELETE",
35
+ headers: await this._client.headers(),
36
+ signal: AbortSignal.timeout(30_000),
37
+ });
38
+ }
39
+ async listDocuments() {
40
+ const url = new URL("v1/rag/documents", this._client.getHttpBase());
41
+ const response = await (0, utils_ts_1.fetchOrThrow)(url, {
42
+ headers: await this._client.headers(),
43
+ signal: AbortSignal.timeout(30_000),
44
+ });
45
+ return (await response.json());
46
+ }
47
+ async ask(question, { documentKeys, instructions } = {}) {
48
+ const url = new URL("v1/rag/ask", this._client.getHttpBase());
49
+ const payload = { question };
50
+ if (documentKeys !== undefined)
51
+ payload.document_keys = documentKeys;
52
+ if (instructions !== undefined)
53
+ payload.instructions = instructions;
54
+ const response = await (0, utils_ts_1.fetchOrThrow)(url, {
55
+ method: "POST",
56
+ headers: { ...(await this._client.headers()), "Content-Type": "application/json" },
57
+ body: JSON.stringify(payload),
58
+ signal: AbortSignal.timeout(120_000),
59
+ });
60
+ const result = (await response.json());
61
+ if (result.warning)
62
+ console.warn(`Guava RAG: ${result.warning}`);
63
+ return result.answer;
64
+ }
65
+ async reconcile(documents, ids) {
66
+ if (ids !== undefined && ids.length !== documents.length) {
67
+ throw new Error(`ids length (${ids.length}) must match documents length (${documents.length})`);
68
+ }
69
+ const desired = new Map();
70
+ if (ids !== undefined) {
71
+ for (let i = 0; i < documents.length; i++) {
72
+ desired.set(_prefixedKey(this._namespace, ids[i]), documents[i]);
73
+ }
74
+ }
75
+ else {
76
+ for (const doc of documents) {
77
+ desired.set(_prefixedKey(this._namespace, _contentKey(doc)), doc);
78
+ }
79
+ }
80
+ const existing = await this.listDocuments();
81
+ const existingKeys = new Set(existing.map((d) => d.key));
82
+ const scopedKeys = this._namespace
83
+ ? new Set([...existingKeys].filter((k) => k.startsWith(`${this._namespace}.`)))
84
+ : existingKeys;
85
+ for (const [key, doc] of desired) {
86
+ if (ids !== undefined || !existingKeys.has(key)) {
87
+ await this.uploadDocument(key, doc);
88
+ }
89
+ this.trackedKeys.add(key);
90
+ }
91
+ const stale = [...scopedKeys].filter((k) => !desired.has(k));
92
+ for (const key of stale) {
93
+ await this.deleteDocument(key);
94
+ }
95
+ }
96
+ async upsertDocument(key, text) {
97
+ const fullKey = _prefixedKey(this._namespace, key);
98
+ await this.uploadDocument(fullKey, text);
99
+ this.trackedKeys.add(fullKey);
100
+ }
101
+ async addDocument(text) {
102
+ const fullKey = _prefixedKey(this._namespace, _contentKey(text));
103
+ await this.uploadDocument(fullKey, text);
104
+ this.trackedKeys.add(fullKey);
105
+ }
106
+ async removeDocument(key) {
107
+ const fullKey = _prefixedKey(this._namespace, key);
108
+ await this.deleteDocument(fullKey);
109
+ this.trackedKeys.delete(fullKey);
110
+ }
111
+ async clear() {
112
+ for (const key of this.trackedKeys) {
113
+ await this.deleteDocument(key);
114
+ }
115
+ this.trackedKeys.clear();
116
+ }
117
+ }
118
+ exports.ServerRAG = ServerRAG;
119
+ //# sourceMappingURL=server-rag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-rag.js","sourceRoot":"","sources":["../../../src/helpers/server-rag.ts"],"names":[],"mappings":";;;AAIA,kCAEC;AAED,oCAEC;AAVD,6CAAyC;AAEzC,0CAA2C;AAE3C,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,SAAgB,YAAY,CAAC,SAA6B,EAAE,GAAW;IACrE,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACjD,CAAC;AAED,MAAa,SAAS;IACH,OAAO,CAAS;IAChB,UAAU,CAAqB;IACvC,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAEzC,YAAY,MAAc,EAAE,EAAE,SAAS,KAA6B,EAAE;QACpE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,IAAY;QAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QACpE,MAAM,IAAA,uBAAY,EAAC,GAAG,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3
3
  unknown: "unknown";
4
- done: "done";
5
4
  "authentication-failure": "authentication-failure";
6
5
  "state-lost": "state-lost";
6
+ done: "done";
7
7
  other: "other";
8
8
  "server-error": "server-error";
9
9
  "reconnection-failed": "reconnection-failed";
@@ -27,9 +27,9 @@ export declare const GuavaClose: z.ZodObject<{
27
27
  message_type: z.ZodLiteral<"close">;
28
28
  reason: z.ZodEnum<{
29
29
  unknown: "unknown";
30
- done: "done";
31
30
  "authentication-failure": "authentication-failure";
32
31
  "state-lost": "state-lost";
32
+ done: "done";
33
33
  other: "other";
34
34
  "server-error": "server-error";
35
35
  "reconnection-failed": "reconnection-failed";
@@ -69,9 +69,9 @@ export declare const GuavaClientMessage: z.ZodDiscriminatedUnion<[z.ZodObject<{
69
69
  message_type: z.ZodLiteral<"close">;
70
70
  reason: z.ZodEnum<{
71
71
  unknown: "unknown";
72
- done: "done";
73
72
  "authentication-failure": "authentication-failure";
74
73
  "state-lost": "state-lost";
74
+ done: "done";
75
75
  other: "other";
76
76
  "server-error": "server-error";
77
77
  "reconnection-failed": "reconnection-failed";
@@ -101,9 +101,9 @@ export declare const GuavaServerMessage: z.ZodDiscriminatedUnion<[z.ZodObject<{
101
101
  message_type: z.ZodLiteral<"close">;
102
102
  reason: z.ZodEnum<{
103
103
  unknown: "unknown";
104
- done: "done";
105
104
  "authentication-failure": "authentication-failure";
106
105
  "state-lost": "state-lost";
106
+ done: "done";
107
107
  other: "other";
108
108
  "server-error": "server-error";
109
109
  "reconnection-failed": "reconnection-failed";
@@ -1,6 +1,12 @@
1
1
  import { Call } from "../call.ts";
2
+ import type { CallInfo } from "../socket/call-info.ts";
2
3
  import type { Command } from "../commands.ts";
3
4
  export declare class MockCall extends Call {
5
+ constructor(args?: {
6
+ callId?: string;
7
+ callInfo?: CallInfo;
8
+ variables?: Record<string, any>;
9
+ });
4
10
  get commands(): Command[];
5
11
  setField(fieldName: string, fieldValue: unknown): void;
6
12
  }