@diegoaltoworks/chatter 0.45.0 → 0.48.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/README.md +19 -5
- package/dist/auth/apikeys.d.ts.map +1 -1
- package/dist/auth/secretStrength.d.ts +8 -0
- package/dist/auth/secretStrength.d.ts.map +1 -0
- package/dist/bin/create-apikey.js +22 -3
- package/dist/bin/wa-pair.js +59 -11
- package/dist/channels/gates.d.ts +9 -0
- package/dist/channels/gates.d.ts.map +1 -1
- package/dist/channels/index.d.ts +1 -0
- package/dist/channels/index.d.ts.map +1 -1
- package/dist/channels/index.js +252 -8
- package/dist/channels/index.mjs +250 -8
- package/dist/channels/pipeline.d.ts +106 -0
- package/dist/channels/pipeline.d.ts.map +1 -0
- package/dist/channels/senders.d.ts +2 -1
- package/dist/channels/senders.d.ts.map +1 -1
- package/dist/channels/whatsapp/channel.d.ts +4 -0
- package/dist/channels/whatsapp/channel.d.ts.map +1 -1
- package/dist/channels/whatsapp/crypto.d.ts +17 -3
- package/dist/channels/whatsapp/crypto.d.ts.map +1 -1
- package/dist/channels/whatsapp/inbound.d.ts +34 -4
- package/dist/channels/whatsapp/inbound.d.ts.map +1 -1
- package/dist/channels/whatsapp/index.d.ts +2 -1
- package/dist/channels/whatsapp/index.d.ts.map +1 -1
- package/dist/channels/whatsapp/index.js +395 -159
- package/dist/channels/whatsapp/index.mjs +394 -160
- package/dist/channels/whatsapp/router.d.ts +107 -0
- package/dist/channels/whatsapp/router.d.ts.map +1 -0
- package/dist/core/answer.d.ts +5 -2
- package/dist/core/answer.d.ts.map +1 -1
- package/dist/core/logger.d.ts +23 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/messages.d.ts +8 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/pipeline.d.ts +2 -0
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/retrieval.d.ts +4 -0
- package/dist/core/retrieval.d.ts.map +1 -1
- package/dist/core/serve-static.d.ts +38 -0
- package/dist/core/serve-static.d.ts.map +1 -0
- package/dist/flows/engine.d.ts +3 -0
- package/dist/flows/engine.d.ts.map +1 -1
- package/dist/flows/index.d.ts +1 -0
- package/dist/flows/index.d.ts.map +1 -1
- package/dist/flows/index.js +91 -25
- package/dist/flows/index.mjs +91 -26
- package/dist/flows/intent.d.ts +2 -1
- package/dist/flows/intent.d.ts.map +1 -1
- package/dist/flows/loader.d.ts +5 -3
- package/dist/flows/loader.d.ts.map +1 -1
- package/dist/flows/types.d.ts +9 -0
- package/dist/flows/types.d.ts.map +1 -1
- package/dist/history/index.d.ts +17 -0
- package/dist/history/index.d.ts.map +1 -0
- package/dist/history/index.js +100 -0
- package/dist/history/index.mjs +73 -0
- package/dist/history/tursoStore.d.ts +26 -0
- package/dist/history/tursoStore.d.ts.map +1 -0
- package/dist/history/types.d.ts +18 -0
- package/dist/history/types.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1202 -32462
- package/dist/index.mjs +1118 -32414
- package/dist/mcp-server/cost-tracker.d.ts +11 -6
- package/dist/mcp-server/cost-tracker.d.ts.map +1 -1
- package/dist/mcp-server/logger.d.ts +5 -2
- package/dist/mcp-server/logger.d.ts.map +1 -1
- package/dist/mcp-server/sdk.d.ts +23 -0
- package/dist/mcp-server/sdk.d.ts.map +1 -0
- package/dist/mcp-server/tool-input.d.ts +12 -0
- package/dist/mcp-server/tool-input.d.ts.map +1 -0
- package/dist/mcp-server/types.d.ts +10 -3
- package/dist/mcp-server/types.d.ts.map +1 -1
- package/dist/mcp-server.d.ts +1 -2
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +192 -111
- package/dist/mcp-server.mjs +179 -98
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/bodyLimit.d.ts +11 -0
- package/dist/middleware/bodyLimit.d.ts.map +1 -0
- package/dist/middleware/clientKey.d.ts +15 -0
- package/dist/middleware/clientKey.d.ts.map +1 -0
- package/dist/middleware/cors.d.ts.map +1 -1
- package/dist/middleware/jwt.d.ts +0 -3
- package/dist/middleware/jwt.d.ts.map +1 -1
- package/dist/middleware/originMatch.d.ts +27 -0
- package/dist/middleware/originMatch.d.ts.map +1 -0
- package/dist/middleware/ratelimit.d.ts +0 -6
- package/dist/middleware/ratelimit.d.ts.map +1 -1
- package/dist/middleware/referrer.d.ts +5 -1
- package/dist/middleware/referrer.d.ts.map +1 -1
- package/dist/middleware/securityHeaders.d.ts +20 -0
- package/dist/middleware/securityHeaders.d.ts.map +1 -0
- package/dist/middleware/session.d.ts +2 -1
- package/dist/middleware/session.d.ts.map +1 -1
- package/dist/middleware/windowBucket.d.ts +19 -0
- package/dist/middleware/windowBucket.d.ts.map +1 -0
- package/dist/personas/index.js +20 -1
- package/dist/personas/index.mjs +20 -1
- package/dist/personas/resolver.d.ts +3 -0
- package/dist/personas/resolver.d.ts.map +1 -1
- package/dist/routes/demo.d.ts.map +1 -1
- package/dist/routes/openai.d.ts.map +1 -1
- package/dist/routes/private.d.ts.map +1 -1
- package/dist/routes/public.d.ts.map +1 -1
- package/dist/scheduler/compose.d.ts +2 -1
- package/dist/scheduler/compose.d.ts.map +1 -1
- package/dist/scheduler/index.js +29 -9
- package/dist/scheduler/index.mjs +29 -9
- package/dist/scheduler/scheduler.d.ts +3 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -1
- package/dist/scheduler/tick.d.ts +2 -0
- package/dist/scheduler/tick.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +726 -538
- package/dist/server.mjs +708 -527
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +30 -9
package/dist/flows/index.mjs
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
// src/core/logger.ts
|
|
2
|
+
var LEVEL_ORDER = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
3
|
+
function createConsoleLogger(level = "info") {
|
|
4
|
+
const threshold = LEVEL_ORDER[level];
|
|
5
|
+
const write = (at) => (...args) => {
|
|
6
|
+
if (LEVEL_ORDER[at] < threshold) return;
|
|
7
|
+
console.error(`[${at}]`, ...args);
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
debug: write("debug"),
|
|
11
|
+
info: write("info"),
|
|
12
|
+
warn: write("warn"),
|
|
13
|
+
error: write("error")
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
// src/flows/intent.ts
|
|
2
|
-
async function detectIntent(client, model, message, flows, conversationContext) {
|
|
18
|
+
async function detectIntent(client, model, message, flows, conversationContext, logger = createConsoleLogger()) {
|
|
3
19
|
const contextStr = conversationContext && conversationContext.length > 0 ? `
|
|
4
20
|
|
|
5
21
|
Recent conversation:
|
|
@@ -42,7 +58,7 @@ Rules:
|
|
|
42
58
|
const confidence = typeof raw.confidence === "number" ? raw.confidence : 0;
|
|
43
59
|
return { intent, confidence, reasoning: raw.reasoning };
|
|
44
60
|
} catch (error) {
|
|
45
|
-
|
|
61
|
+
logger.warn(
|
|
46
62
|
`[flows] intent detection failed: ${error instanceof Error ? error.message : String(error)}`
|
|
47
63
|
);
|
|
48
64
|
return { intent: "chatbot", confidence: 0, reasoning: "exception, defaulting to chatbot" };
|
|
@@ -51,69 +67,109 @@ Rules:
|
|
|
51
67
|
|
|
52
68
|
// src/flows/loader.ts
|
|
53
69
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
54
|
-
import { join, resolve } from "node:path";
|
|
70
|
+
import { basename, join, resolve } from "node:path";
|
|
71
|
+
|
|
72
|
+
// src/flows/types.ts
|
|
73
|
+
var CURRENT_FLOW_CONTRACT_VERSION = 1;
|
|
74
|
+
|
|
75
|
+
// src/flows/loader.ts
|
|
55
76
|
var SKIPPED_DIR_NAMES = /* @__PURE__ */ new Set(["lib", "tests", "registry"]);
|
|
56
|
-
|
|
77
|
+
var MODULE_EXTENSIONS = ["ts", "js", "mjs"];
|
|
78
|
+
async function loadFlowsFromDirectory(flowsDir, logger = createConsoleLogger()) {
|
|
57
79
|
const flows = /* @__PURE__ */ new Map();
|
|
58
80
|
if (!existsSync(flowsDir)) {
|
|
59
|
-
|
|
81
|
+
logger.warn(`[flows] directory does not exist: ${flowsDir}`);
|
|
60
82
|
return flows;
|
|
61
83
|
}
|
|
62
84
|
const flowDirs = readdirSync(flowsDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).filter((dirent) => !SKIPPED_DIR_NAMES.has(dirent.name)).map((dirent) => dirent.name);
|
|
63
85
|
for (const flowName of flowDirs) {
|
|
64
86
|
try {
|
|
65
|
-
flows.set(flowName, await loadFlow(flowsDir, flowName));
|
|
87
|
+
flows.set(flowName, await loadFlow(flowsDir, flowName, logger));
|
|
66
88
|
} catch (error) {
|
|
67
|
-
|
|
89
|
+
logger.warn(
|
|
68
90
|
`[flows] failed to load "${flowName}": ${error instanceof Error ? error.message : String(error)}`
|
|
69
91
|
);
|
|
70
92
|
}
|
|
71
93
|
}
|
|
72
94
|
return flows;
|
|
73
95
|
}
|
|
74
|
-
|
|
96
|
+
function validateFlowDefinition(raw, flowName) {
|
|
97
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
98
|
+
throw new Error(`flow.json for "${flowName}" must be a JSON object`);
|
|
99
|
+
}
|
|
100
|
+
const definition = raw;
|
|
101
|
+
if (typeof definition.id !== "string" || definition.id.length === 0) {
|
|
102
|
+
throw new Error(`flow.json for "${flowName}": "id" must be a non-empty string`);
|
|
103
|
+
}
|
|
104
|
+
if (!Array.isArray(definition.triggerKeywords) || definition.triggerKeywords.length === 0) {
|
|
105
|
+
throw new Error(`flow.json for "${flowName}": "triggerKeywords" must be a non-empty array`);
|
|
106
|
+
}
|
|
107
|
+
const properties = definition.schema?.properties;
|
|
108
|
+
if (!properties || typeof properties !== "object" || Array.isArray(properties) || Object.keys(properties).length === 0) {
|
|
109
|
+
throw new Error(`flow.json for "${flowName}": "schema.properties" must be a non-empty object`);
|
|
110
|
+
}
|
|
111
|
+
if (definition.contractVersion !== void 0) {
|
|
112
|
+
const version = definition.contractVersion;
|
|
113
|
+
if (!Number.isInteger(version) || version < 1 || version > CURRENT_FLOW_CONTRACT_VERSION) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`flow.json for "${flowName}": "contractVersion" ${JSON.stringify(version)} is not supported (this loader understands versions 1 through ${CURRENT_FLOW_CONTRACT_VERSION})`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function loadFlow(flowsDir, flowName, logger) {
|
|
75
121
|
const flowPath = resolve(flowsDir, flowName);
|
|
76
122
|
const definitionPath = join(flowPath, "flow.json");
|
|
77
123
|
const instructionsPath = join(flowPath, "instructions.md");
|
|
78
|
-
const handlerPath = join(flowPath, "handler.ts");
|
|
79
124
|
if (!existsSync(definitionPath)) {
|
|
80
125
|
throw new Error(`flow.json not found for ${flowName}`);
|
|
81
126
|
}
|
|
82
127
|
if (!existsSync(instructionsPath)) {
|
|
83
128
|
throw new Error(`instructions.md not found for ${flowName}`);
|
|
84
129
|
}
|
|
85
|
-
|
|
86
|
-
|
|
130
|
+
const handlerPath = findModulePath(flowPath, "handler");
|
|
131
|
+
if (!handlerPath) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`no handler found for ${flowName} (looked for ${MODULE_EXTENSIONS.map((ext) => `handler.${ext}`).join(", ")})`
|
|
134
|
+
);
|
|
87
135
|
}
|
|
88
|
-
const
|
|
136
|
+
const rawDefinition = JSON.parse(readFileSync(definitionPath, "utf-8"));
|
|
137
|
+
validateFlowDefinition(rawDefinition, flowName);
|
|
138
|
+
const definition = {
|
|
139
|
+
...rawDefinition,
|
|
140
|
+
contractVersion: rawDefinition.contractVersion ?? CURRENT_FLOW_CONTRACT_VERSION
|
|
141
|
+
};
|
|
89
142
|
if (definition.id !== flowName) {
|
|
90
143
|
throw new Error(`Flow id mismatch: ${definition.id} !== ${flowName}`);
|
|
91
144
|
}
|
|
92
|
-
if (!definition.triggerKeywords || definition.triggerKeywords.length === 0) {
|
|
93
|
-
throw new Error(`Flow ${flowName} has no trigger keywords`);
|
|
94
|
-
}
|
|
95
|
-
if (!definition.schema || Object.keys(definition.schema.properties ?? {}).length === 0) {
|
|
96
|
-
throw new Error(`Flow ${flowName} has no schema`);
|
|
97
|
-
}
|
|
98
145
|
const handlerModule = await import(handlerPath);
|
|
99
146
|
const handler = handlerModule.execute;
|
|
100
147
|
if (typeof handler !== "function") {
|
|
101
|
-
throw new Error(`Flow ${flowName}
|
|
148
|
+
throw new Error(`Flow ${flowName} ${basename(handlerPath)} must export an 'execute' function`);
|
|
102
149
|
}
|
|
103
|
-
const prefillPath =
|
|
150
|
+
const prefillPath = findModulePath(flowPath, "prefill");
|
|
104
151
|
let prefill;
|
|
105
|
-
if (
|
|
152
|
+
if (prefillPath) {
|
|
106
153
|
const prefillModule = await import(prefillPath);
|
|
107
154
|
if (typeof prefillModule.prefillFromContext === "function") {
|
|
108
155
|
prefill = prefillModule.prefillFromContext;
|
|
109
156
|
} else {
|
|
110
|
-
|
|
111
|
-
`[flows] "${flowName}"
|
|
157
|
+
logger.warn(
|
|
158
|
+
`[flows] "${flowName}" ${basename(prefillPath)} does not export a prefillFromContext function`
|
|
112
159
|
);
|
|
113
160
|
}
|
|
114
161
|
}
|
|
115
162
|
return { definition, handler, instructionsPath, prefill };
|
|
116
163
|
}
|
|
164
|
+
function findModulePath(flowPath, base) {
|
|
165
|
+
for (const ext of MODULE_EXTENSIONS) {
|
|
166
|
+
const candidate = join(flowPath, `${base}.${ext}`);
|
|
167
|
+
if (existsSync(candidate)) {
|
|
168
|
+
return candidate;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
117
173
|
|
|
118
174
|
// src/flows/params.ts
|
|
119
175
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
@@ -256,7 +312,8 @@ function createFlowEngine(options) {
|
|
|
256
312
|
cancelMessage = DEFAULT_CANCEL_MESSAGE,
|
|
257
313
|
errorMessage = DEFAULT_ERROR_MESSAGE,
|
|
258
314
|
sessionTtlMs,
|
|
259
|
-
now = Date.now
|
|
315
|
+
now = Date.now,
|
|
316
|
+
logger = createConsoleLogger()
|
|
260
317
|
} = options;
|
|
261
318
|
let registry = createFlowRegistry(/* @__PURE__ */ new Map());
|
|
262
319
|
async function matchFlow(message, conversationContext) {
|
|
@@ -265,7 +322,14 @@ function createFlowEngine(options) {
|
|
|
265
322
|
const allFlows = registry.getAllFlows();
|
|
266
323
|
if (allFlows.length === 0) return void 0;
|
|
267
324
|
const flowMap = new Map(allFlows.map((flow) => [flow.definition.id, flow]));
|
|
268
|
-
const detection = await detectIntent(
|
|
325
|
+
const detection = await detectIntent(
|
|
326
|
+
client,
|
|
327
|
+
model,
|
|
328
|
+
message,
|
|
329
|
+
flowMap,
|
|
330
|
+
conversationContext,
|
|
331
|
+
logger
|
|
332
|
+
);
|
|
269
333
|
if (detection.confidence >= minConfidence) {
|
|
270
334
|
return registry.getFlow(detection.intent);
|
|
271
335
|
}
|
|
@@ -299,7 +363,7 @@ function createFlowEngine(options) {
|
|
|
299
363
|
}
|
|
300
364
|
return {
|
|
301
365
|
async loadFlows() {
|
|
302
|
-
const flows = await loadFlowsFromDirectory(flowsDir);
|
|
366
|
+
const flows = await loadFlowsFromDirectory(flowsDir, logger);
|
|
303
367
|
registry = createFlowRegistry(flows, criticalKeywords);
|
|
304
368
|
},
|
|
305
369
|
getFlow(id) {
|
|
@@ -438,6 +502,7 @@ function createTursoFlowSessionStore(client, tableName = "flow_sessions") {
|
|
|
438
502
|
};
|
|
439
503
|
}
|
|
440
504
|
export {
|
|
505
|
+
CURRENT_FLOW_CONTRACT_VERSION,
|
|
441
506
|
createFlowEngine,
|
|
442
507
|
createFlowRegistry,
|
|
443
508
|
createTursoFlowSessionStore,
|
package/dist/flows/intent.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* the same client tests already fake for chat completions covers this too).
|
|
5
5
|
*/
|
|
6
6
|
import type OpenAI from "openai";
|
|
7
|
+
import { type Logger } from "../core/logger";
|
|
7
8
|
import type { IntentDetection, LoadedFlow } from "./types";
|
|
8
9
|
/** Detects which loaded flow (if any) a message expresses intent for. */
|
|
9
|
-
export declare function detectIntent(client: OpenAI, model: string, message: string, flows: Map<string, LoadedFlow>, conversationContext?: string[]): Promise<IntentDetection>;
|
|
10
|
+
export declare function detectIntent(client: OpenAI, model: string, message: string, flows: Map<string, LoadedFlow>, conversationContext?: string[], logger?: Logger): Promise<IntentDetection>;
|
|
10
11
|
//# sourceMappingURL=intent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/flows/intent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,yEAAyE;AACzE,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/flows/intent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,yEAAyE;AACzE,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAC9B,MAAM,GAAE,MAA8B,GACrC,OAAO,CAAC,eAAe,CAAC,CAyD1B"}
|
package/dist/flows/loader.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directory-based flow loader.
|
|
3
3
|
*
|
|
4
|
-
* Discovers flow directories on disk and loads each one's contract
|
|
5
|
-
*
|
|
4
|
+
* Discovers flow directories on disk and loads each one's contract, validated
|
|
5
|
+
* against the versioned flow.json contract (see {@link CURRENT_FLOW_CONTRACT_VERSION}
|
|
6
|
+
* in ./types). Kept compatible with the reference implementation's on-disk
|
|
6
7
|
* shape, so existing flow directories load unchanged.
|
|
7
8
|
*/
|
|
9
|
+
import { type Logger } from "../core/logger";
|
|
8
10
|
import type { LoadedFlow } from "./types";
|
|
9
11
|
/** Loads every flow directory under `flowsDir`. A flow that fails to load is skipped, not fatal to the rest. */
|
|
10
|
-
export declare function loadFlowsFromDirectory(flowsDir: string): Promise<Map<string, LoadedFlow>>;
|
|
12
|
+
export declare function loadFlowsFromDirectory(flowsDir: string, logger?: Logger): Promise<Map<string, LoadedFlow>>;
|
|
11
13
|
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/flows/loader.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/flows/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAA4C,UAAU,EAAE,MAAM,SAAS,CAAC;AAQpF,gHAAgH;AAChH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAA8B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAwBlC"}
|
package/dist/flows/types.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export interface FlowSchema {
|
|
|
17
17
|
properties: Record<string, FlowSchemaProperty>;
|
|
18
18
|
required: string[];
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Highest `contractVersion` this loader understands. A flow.json omitting
|
|
22
|
+
* `contractVersion` is treated as version 1 (every flow written before this
|
|
23
|
+
* field existed); a flow.json naming a version above this one fails to load
|
|
24
|
+
* with an actionable error rather than being silently misinterpreted.
|
|
25
|
+
*/
|
|
26
|
+
export declare const CURRENT_FLOW_CONTRACT_VERSION = 1;
|
|
20
27
|
/** Parsed `flow.json`. */
|
|
21
28
|
export interface FlowDefinition {
|
|
22
29
|
id: string;
|
|
@@ -24,6 +31,8 @@ export interface FlowDefinition {
|
|
|
24
31
|
description: string;
|
|
25
32
|
triggerKeywords: string[];
|
|
26
33
|
schema: FlowSchema;
|
|
34
|
+
/** Defaults to 1 when omitted. See {@link CURRENT_FLOW_CONTRACT_VERSION}. */
|
|
35
|
+
contractVersion?: number;
|
|
27
36
|
}
|
|
28
37
|
/** What a handler is given alongside the collected params. */
|
|
29
38
|
export interface FlowHandlerContext {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/flows/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,0BAA0B;AAC1B,MAAM,WAAW,cAAc;I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,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation history — a structural, host-replaceable store for multi-turn
|
|
3
|
+
* context, following the `FlowSessionStore`/`DailyLimitsStore` pattern.
|
|
4
|
+
* Published as the `@diegoaltoworks/chatter/history` subpath so the core
|
|
5
|
+
* install stays untouched by it, and so every channel stays single-turn
|
|
6
|
+
* until it opts in.
|
|
7
|
+
*
|
|
8
|
+
* The interface is deliberately small — `append`/`load(conversationId,
|
|
9
|
+
* limit)` — so any backing store (Turso, Redis, a host's own database) can
|
|
10
|
+
* implement it. The shipped Turso implementation needs `@libsql/client`,
|
|
11
|
+
* which chatter already expects for retrieval.
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
export { createTursoHistoryStore } from "./tursoStore";
|
|
16
|
+
export type { HistoryMessage, HistoryStore } from "./types";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/history/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createTursoHistoryStore: () => createTursoHistoryStore
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/history/tursoStore.ts
|
|
28
|
+
var schemaReady = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
function ensureHistorySchema(client, tableName) {
|
|
30
|
+
let perTable = schemaReady.get(client);
|
|
31
|
+
if (!perTable) {
|
|
32
|
+
perTable = /* @__PURE__ */ new Map();
|
|
33
|
+
schemaReady.set(client, perTable);
|
|
34
|
+
}
|
|
35
|
+
const tables = perTable;
|
|
36
|
+
let ready = tables.get(tableName);
|
|
37
|
+
if (!ready) {
|
|
38
|
+
ready = client.execute(
|
|
39
|
+
`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
40
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
41
|
+
conversation_id TEXT NOT NULL,
|
|
42
|
+
role TEXT NOT NULL,
|
|
43
|
+
content TEXT NOT NULL,
|
|
44
|
+
created_at INTEGER NOT NULL
|
|
45
|
+
)`
|
|
46
|
+
).then(
|
|
47
|
+
() => client.execute(
|
|
48
|
+
`CREATE INDEX IF NOT EXISTS ${tableName}_conversation_idx ON ${tableName} (conversation_id, id)`
|
|
49
|
+
)
|
|
50
|
+
).catch((error) => {
|
|
51
|
+
tables.delete(tableName);
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
54
|
+
tables.set(tableName, ready);
|
|
55
|
+
}
|
|
56
|
+
return ready;
|
|
57
|
+
}
|
|
58
|
+
var VALID_TABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
59
|
+
var VALID_ROLES = /* @__PURE__ */ new Set(["user", "assistant"]);
|
|
60
|
+
var DEFAULT_MAX_PER_CONVERSATION = 200;
|
|
61
|
+
function createTursoHistoryStore(client, tableName = "chat_history", maxPerConversation = DEFAULT_MAX_PER_CONVERSATION) {
|
|
62
|
+
if (!VALID_TABLE_NAME.test(tableName)) {
|
|
63
|
+
throw new Error(`Invalid history store table name: ${tableName}`);
|
|
64
|
+
}
|
|
65
|
+
if (!Number.isInteger(maxPerConversation) || maxPerConversation < 1) {
|
|
66
|
+
throw new Error(`Invalid history store maxPerConversation: ${maxPerConversation}`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
async append(conversationId, message) {
|
|
70
|
+
await ensureHistorySchema(client, tableName);
|
|
71
|
+
await client.execute({
|
|
72
|
+
sql: `INSERT INTO ${tableName} (conversation_id, role, content, created_at) VALUES (?, ?, ?, ?)`,
|
|
73
|
+
args: [conversationId, message.role, message.content, Date.now()]
|
|
74
|
+
});
|
|
75
|
+
await client.execute({
|
|
76
|
+
sql: `DELETE FROM ${tableName} WHERE conversation_id = ? AND id NOT IN (
|
|
77
|
+
SELECT id FROM ${tableName} WHERE conversation_id = ? ORDER BY id DESC LIMIT ?
|
|
78
|
+
)`,
|
|
79
|
+
args: [conversationId, conversationId, maxPerConversation]
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
async load(conversationId, limit) {
|
|
83
|
+
const boundedLimit = Math.max(0, Math.trunc(limit));
|
|
84
|
+
if (boundedLimit === 0) return [];
|
|
85
|
+
await ensureHistorySchema(client, tableName);
|
|
86
|
+
const result = await client.execute({
|
|
87
|
+
sql: `SELECT role, content FROM ${tableName} WHERE conversation_id = ? ORDER BY id DESC LIMIT ?`,
|
|
88
|
+
args: [conversationId, boundedLimit]
|
|
89
|
+
});
|
|
90
|
+
return result.rows.map((row) => ({
|
|
91
|
+
role: String(row.role),
|
|
92
|
+
content: String(row.content)
|
|
93
|
+
})).filter((row) => VALID_ROLES.has(row.role)).reverse();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
createTursoHistoryStore
|
|
100
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/history/tursoStore.ts
|
|
2
|
+
var schemaReady = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function ensureHistorySchema(client, tableName) {
|
|
4
|
+
let perTable = schemaReady.get(client);
|
|
5
|
+
if (!perTable) {
|
|
6
|
+
perTable = /* @__PURE__ */ new Map();
|
|
7
|
+
schemaReady.set(client, perTable);
|
|
8
|
+
}
|
|
9
|
+
const tables = perTable;
|
|
10
|
+
let ready = tables.get(tableName);
|
|
11
|
+
if (!ready) {
|
|
12
|
+
ready = client.execute(
|
|
13
|
+
`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
14
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15
|
+
conversation_id TEXT NOT NULL,
|
|
16
|
+
role TEXT NOT NULL,
|
|
17
|
+
content TEXT NOT NULL,
|
|
18
|
+
created_at INTEGER NOT NULL
|
|
19
|
+
)`
|
|
20
|
+
).then(
|
|
21
|
+
() => client.execute(
|
|
22
|
+
`CREATE INDEX IF NOT EXISTS ${tableName}_conversation_idx ON ${tableName} (conversation_id, id)`
|
|
23
|
+
)
|
|
24
|
+
).catch((error) => {
|
|
25
|
+
tables.delete(tableName);
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
tables.set(tableName, ready);
|
|
29
|
+
}
|
|
30
|
+
return ready;
|
|
31
|
+
}
|
|
32
|
+
var VALID_TABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
33
|
+
var VALID_ROLES = /* @__PURE__ */ new Set(["user", "assistant"]);
|
|
34
|
+
var DEFAULT_MAX_PER_CONVERSATION = 200;
|
|
35
|
+
function createTursoHistoryStore(client, tableName = "chat_history", maxPerConversation = DEFAULT_MAX_PER_CONVERSATION) {
|
|
36
|
+
if (!VALID_TABLE_NAME.test(tableName)) {
|
|
37
|
+
throw new Error(`Invalid history store table name: ${tableName}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isInteger(maxPerConversation) || maxPerConversation < 1) {
|
|
40
|
+
throw new Error(`Invalid history store maxPerConversation: ${maxPerConversation}`);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
async append(conversationId, message) {
|
|
44
|
+
await ensureHistorySchema(client, tableName);
|
|
45
|
+
await client.execute({
|
|
46
|
+
sql: `INSERT INTO ${tableName} (conversation_id, role, content, created_at) VALUES (?, ?, ?, ?)`,
|
|
47
|
+
args: [conversationId, message.role, message.content, Date.now()]
|
|
48
|
+
});
|
|
49
|
+
await client.execute({
|
|
50
|
+
sql: `DELETE FROM ${tableName} WHERE conversation_id = ? AND id NOT IN (
|
|
51
|
+
SELECT id FROM ${tableName} WHERE conversation_id = ? ORDER BY id DESC LIMIT ?
|
|
52
|
+
)`,
|
|
53
|
+
args: [conversationId, conversationId, maxPerConversation]
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async load(conversationId, limit) {
|
|
57
|
+
const boundedLimit = Math.max(0, Math.trunc(limit));
|
|
58
|
+
if (boundedLimit === 0) return [];
|
|
59
|
+
await ensureHistorySchema(client, tableName);
|
|
60
|
+
const result = await client.execute({
|
|
61
|
+
sql: `SELECT role, content FROM ${tableName} WHERE conversation_id = ? ORDER BY id DESC LIMIT ?`,
|
|
62
|
+
args: [conversationId, boundedLimit]
|
|
63
|
+
});
|
|
64
|
+
return result.rows.map((row) => ({
|
|
65
|
+
role: String(row.role),
|
|
66
|
+
content: String(row.content)
|
|
67
|
+
})).filter((row) => VALID_ROLES.has(row.role)).reverse();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
createTursoHistoryStore
|
|
73
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso/libsql-backed {@link HistoryStore}.
|
|
3
|
+
*
|
|
4
|
+
* History lives in the database rather than process memory because
|
|
5
|
+
* deployments run multiple instances — the instance that handles turn 2 of a
|
|
6
|
+
* conversation is not guaranteed to be the one that handled turn 1.
|
|
7
|
+
*
|
|
8
|
+
* `@libsql/client` is imported for its type alone, so this module adds no
|
|
9
|
+
* runtime dependency to anyone importing `./history` for the store contract.
|
|
10
|
+
*/
|
|
11
|
+
import type { Client } from "@libsql/client";
|
|
12
|
+
import type { HistoryStore } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Creates a history store keyed by an arbitrary conversation id (a WhatsApp
|
|
15
|
+
* chat jid, a phone call sid, a web session id) on `tableName`.
|
|
16
|
+
*
|
|
17
|
+
* `append` prunes each conversation back down to `maxPerConversation` after
|
|
18
|
+
* every write, so the table stays bounded even for a conversation nobody
|
|
19
|
+
* ever calls `load` on with a small `limit` — a caller's `limit` shapes what
|
|
20
|
+
* a single `load` returns, not how much history physically accumulates. A
|
|
21
|
+
* non-positive `maxPerConversation` would prune every write to nothing (`0`)
|
|
22
|
+
* or disable pruning entirely (SQLite reads a negative `LIMIT` as
|
|
23
|
+
* unlimited), so it is validated at construction the same way `tableName` is.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createTursoHistoryStore(client: Client, tableName?: string, maxPerConversation?: number): HistoryStore;
|
|
26
|
+
//# sourceMappingURL=tursoStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tursoStore.d.ts","sourceRoot":"","sources":["../../src/history/tursoStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAC;AAkD5D;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,SAAiB,EAC1B,kBAAkB,SAA+B,GAChD,YAAY,CAkDd"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** One turn of conversation history. */
|
|
2
|
+
export interface HistoryMessage {
|
|
3
|
+
role: "user" | "assistant";
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Structural, host-replaceable conversation history — the `FlowSessionStore`/
|
|
8
|
+
* `DailyLimitsStore` pattern applied to multi-turn context. A channel that
|
|
9
|
+
* knows a `conversationId` loads recent turns before answering and appends
|
|
10
|
+
* the new turn after, rather than each surface hand-rolling its own history.
|
|
11
|
+
*/
|
|
12
|
+
export interface HistoryStore {
|
|
13
|
+
/** Append one turn to `conversationId`'s history. */
|
|
14
|
+
append(conversationId: string, message: HistoryMessage): Promise<void>;
|
|
15
|
+
/** Load up to `limit` most recent turns for `conversationId`, oldest first. */
|
|
16
|
+
load(conversationId: string, limit: number): Promise<HistoryMessage[]>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/history/types.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,+EAA+E;IAC/E,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CACxE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export type { ApiKeyOptions, ApiKeyPayload, VerifyResult } from "./auth";
|
|
|
14
14
|
export { ApiKeyManager } from "./auth";
|
|
15
15
|
export type { Channel } from "./channels";
|
|
16
16
|
export type { ChatBotConfig, ChatButtonConfig, ChatConfig, ChatMessage, ChatMode, StreamCallbacks, } from "./client";
|
|
17
|
-
export { Chat, ChatBot, ChatButton } from "./client";
|
|
18
17
|
export type { AnswerFn, AnswerFnInput, AnswerFnResult, AnswerOptions, AnswerUsage, } from "./core/answer";
|
|
19
18
|
export { answerOnce, answerStream } from "./core/answer";
|
|
20
19
|
export type { BucketsFor, BucketsForContext } from "./core/buckets";
|
|
@@ -22,6 +21,8 @@ export { defaultBuckets, resolveBuckets } from "./core/buckets";
|
|
|
22
21
|
export { detectLeakage, guardOutput, scrubOutput } from "./core/guardrails";
|
|
23
22
|
export { completeOnce, completeStream, DEFAULT_MODEL } from "./core/llm";
|
|
24
23
|
export { loadKnowledge } from "./core/loaders";
|
|
24
|
+
export type { Logger, LogLevel } from "./core/logger";
|
|
25
|
+
export { createConsoleLogger } from "./core/logger";
|
|
25
26
|
export type { NormalizedChatBody } from "./core/messages";
|
|
26
27
|
export { normalizeChatBody, normalizeMessages } from "./core/messages";
|
|
27
28
|
export type { PipelineMessage, PipelineMode, PreparedChat } from "./core/pipeline";
|
|
@@ -33,10 +34,12 @@ export { createSession, getActiveSessions, getSessionInfo, validateSession, } fr
|
|
|
33
34
|
export type { MCPServerOptions, MCPTransportMode } from "./mcp-server";
|
|
34
35
|
export { createMCPServer } from "./mcp-server";
|
|
35
36
|
export { createAuthMiddleware } from "./middleware/auth";
|
|
37
|
+
export { chatBodyLimit } from "./middleware/bodyLimit";
|
|
36
38
|
export { cors } from "./middleware/cors";
|
|
37
39
|
export { createJWTMiddleware, jwtSubject } from "./middleware/jwt";
|
|
38
40
|
export { createRateLimiter } from "./middleware/ratelimit";
|
|
39
41
|
export { createReferrerCheck } from "./middleware/referrer";
|
|
42
|
+
export { securityHeaders } from "./middleware/securityHeaders";
|
|
40
43
|
export { createSessionMiddleware } from "./middleware/session";
|
|
41
44
|
export { demoRoutes } from "./routes/demo";
|
|
42
45
|
export { openaiRoutes } from "./routes/openai";
|
|
@@ -46,5 +49,5 @@ export type { ChatterApp } from "./server";
|
|
|
46
49
|
export { createServer } from "./server";
|
|
47
50
|
export type { Shortener, ShortenerConfig } from "./shortener";
|
|
48
51
|
export { createShortener } from "./shortener";
|
|
49
|
-
export type { BotBranding, BotChatConfig, BotIdentity, ChatterConfig, CustomRoutes, EmbeddingChunk, KnowledgeDocument, ServerDependencies, } from "./types";
|
|
52
|
+
export type { BotBranding, BotChatConfig, BotIdentity, ChatterConfig, CustomRoutes, EmbeddingChunk, KnowledgeDocument, PricingRates, ServerDependencies, } from "./types";
|
|
50
53
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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