@diegoaltoworks/chatter 0.31.0 → 0.32.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/dist/flows/__fixtures__/broken/handler.d.ts +3 -0
- package/dist/flows/__fixtures__/broken/handler.d.ts.map +1 -0
- package/dist/flows/__fixtures__/greeting/handler.d.ts +3 -0
- package/dist/flows/__fixtures__/greeting/handler.d.ts.map +1 -0
- package/dist/flows/__fixtures__/greeting/prefill.d.ts +3 -0
- package/dist/flows/__fixtures__/greeting/prefill.d.ts.map +1 -0
- package/dist/flows/engine.d.ts +54 -0
- package/dist/flows/engine.d.ts.map +1 -0
- package/dist/flows/engine.test.d.ts +9 -0
- package/dist/flows/engine.test.d.ts.map +1 -0
- package/dist/flows/index.d.ts +25 -0
- package/dist/flows/index.d.ts.map +1 -0
- package/dist/flows/index.js +481 -0
- package/dist/flows/index.mjs +448 -0
- package/dist/flows/intent.d.ts +10 -0
- package/dist/flows/intent.d.ts.map +1 -0
- package/dist/flows/intent.test.d.ts +6 -0
- package/dist/flows/intent.test.d.ts.map +1 -0
- package/dist/flows/loader.d.ts +11 -0
- package/dist/flows/loader.d.ts.map +1 -0
- package/dist/flows/loader.test.d.ts +8 -0
- package/dist/flows/loader.test.d.ts.map +1 -0
- package/dist/flows/params.d.ts +15 -0
- package/dist/flows/params.d.ts.map +1 -0
- package/dist/flows/params.test.d.ts +2 -0
- package/dist/flows/params.test.d.ts.map +1 -0
- package/dist/flows/registry.d.ts +22 -0
- package/dist/flows/registry.d.ts.map +1 -0
- package/dist/flows/registry.test.d.ts +2 -0
- package/dist/flows/registry.test.d.ts.map +1 -0
- package/dist/flows/session.d.ts +15 -0
- package/dist/flows/session.d.ts.map +1 -0
- package/dist/flows/session.test.d.ts +7 -0
- package/dist/flows/session.test.d.ts.map +1 -0
- package/dist/flows/types.d.ts +101 -0
- package/dist/flows/types.d.ts.map +1 -0
- package/dist/flows/utils.d.ts +4 -0
- package/dist/flows/utils.d.ts.map +1 -0
- package/dist/flows/utils.test.d.ts +2 -0
- package/dist/flows/utils.test.d.ts.map +1 -0
- package/package.json +8 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flow engine types.
|
|
3
|
+
*
|
|
4
|
+
* A flow is a directory-loaded contract: `flow.json` (id/name/description/
|
|
5
|
+
* triggerKeywords/schema), `handler.ts` (an `execute` export) and
|
|
6
|
+
* `instructions.md` (the prompt fed to parameter extraction), with an
|
|
7
|
+
* optional `prefill.ts` (`prefillFromContext` export). This is the same
|
|
8
|
+
* on-disk shape the reference implementation used — existing flow
|
|
9
|
+
* directories load unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface FlowSchemaProperty {
|
|
12
|
+
type: "string" | "number" | "boolean";
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface FlowSchema {
|
|
16
|
+
type: "object";
|
|
17
|
+
properties: Record<string, FlowSchemaProperty>;
|
|
18
|
+
required: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Parsed `flow.json`. */
|
|
21
|
+
export interface FlowDefinition {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
triggerKeywords: string[];
|
|
26
|
+
schema: FlowSchema;
|
|
27
|
+
}
|
|
28
|
+
/** What a handler is given alongside the collected params. */
|
|
29
|
+
export interface FlowHandlerContext {
|
|
30
|
+
/** Caller-chosen id for this conversation — a phone number, a WhatsApp JID, a web session id. Channel-agnostic by design. */
|
|
31
|
+
sessionKey: string;
|
|
32
|
+
/** Free-form channel label, when the caller knows one. Not interpreted by the engine. */
|
|
33
|
+
channel?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* What a flow hands back once its params are complete.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately presentation-free: no per-channel text. A flow returns one
|
|
39
|
+
* message plus a structured `result`; rendering it for voice, SMS, WhatsApp
|
|
40
|
+
* or anything else is the calling plugin's job, not the engine's.
|
|
41
|
+
*/
|
|
42
|
+
export interface FlowHandlerResult {
|
|
43
|
+
/**
|
|
44
|
+
* Whether the flow itself completed successfully. `success: false` is for
|
|
45
|
+
* "something went wrong that the caller should treat generically" — a flow
|
|
46
|
+
* that wants its own in-persona message for an expected failure (validation,
|
|
47
|
+
* a caught upstream error) should still report `success: true`.
|
|
48
|
+
*/
|
|
49
|
+
success: boolean;
|
|
50
|
+
message: string;
|
|
51
|
+
result?: unknown;
|
|
52
|
+
}
|
|
53
|
+
export type FlowHandler = (params: Record<string, unknown>, context: FlowHandlerContext) => Promise<FlowHandlerResult>;
|
|
54
|
+
/** Seeds params from context before extraction runs — e.g. a caller id already known from the channel. */
|
|
55
|
+
export type FlowPrefill = (sessionKey: string, context: Record<string, unknown>) => Record<string, unknown>;
|
|
56
|
+
export interface LoadedFlow {
|
|
57
|
+
definition: FlowDefinition;
|
|
58
|
+
handler: FlowHandler;
|
|
59
|
+
instructionsPath: string;
|
|
60
|
+
prefill?: FlowPrefill;
|
|
61
|
+
}
|
|
62
|
+
export interface FlowExtractionResult {
|
|
63
|
+
extractedParams: Record<string, unknown>;
|
|
64
|
+
allParamsFilled: boolean;
|
|
65
|
+
nextPrompt?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface IntentDetection {
|
|
68
|
+
intent: string;
|
|
69
|
+
confidence: number;
|
|
70
|
+
reasoning?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Multi-turn state persisted between messages while a flow is collecting params. */
|
|
73
|
+
export interface FlowSessionState {
|
|
74
|
+
flowId: string;
|
|
75
|
+
params: Record<string, unknown>;
|
|
76
|
+
attempts: number;
|
|
77
|
+
startedAt: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Structural dependency for session persistence — a host supplies an
|
|
81
|
+
* implementation (see `./session` for the shipped Turso binding). Must be
|
|
82
|
+
* safe under a multi-instance deployment: state written by one instance has
|
|
83
|
+
* to be visible to whichever instance handles the next message.
|
|
84
|
+
*/
|
|
85
|
+
export interface FlowSessionStore {
|
|
86
|
+
get(sessionKey: string): Promise<FlowSessionState | null>;
|
|
87
|
+
set(sessionKey: string, state: FlowSessionState): Promise<void>;
|
|
88
|
+
clear(sessionKey: string): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
export interface FlowResult {
|
|
91
|
+
isFlowActive: boolean;
|
|
92
|
+
message: string;
|
|
93
|
+
flowCompleted: boolean;
|
|
94
|
+
flowSuccess?: boolean;
|
|
95
|
+
result?: unknown;
|
|
96
|
+
/** The caller cancelled an active flow. */
|
|
97
|
+
cancelled?: boolean;
|
|
98
|
+
/** Flow processing failed (registry lookup, parameter extraction, or handler). */
|
|
99
|
+
error?: boolean;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,8DAA8D;AAC9D,MAAM,WAAW,kBAAkB;IACjC,6HAA6H;IAC7H,UAAU,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MA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AAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,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,4 @@
|
|
|
1
|
+
/** Cancellation-phrase detection, kept separate because it's pure and cheap to check before any LLM call. */
|
|
2
|
+
/** Whether `message` expresses wanting to exit the active flow. */
|
|
3
|
+
export declare function shouldExitFlow(message: string, cancelKeywords?: string[]): boolean;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/flows/utils.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAa7G,mEAAmE;AACnE,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAAM,EAA4B,GACjD,OAAO,CAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/flows/utils.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegoaltoworks/chatter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Embeddable AI chatbot framework with RAG, authentication, and customizable widgets",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -45,6 +45,11 @@
|
|
|
45
45
|
"import": "./dist/channels/index.mjs",
|
|
46
46
|
"require": "./dist/channels/index.js"
|
|
47
47
|
},
|
|
48
|
+
"./flows": {
|
|
49
|
+
"types": "./dist/flows/index.d.ts",
|
|
50
|
+
"import": "./dist/flows/index.mjs",
|
|
51
|
+
"require": "./dist/flows/index.js"
|
|
52
|
+
},
|
|
48
53
|
"./whatsapp": {
|
|
49
54
|
"types": "./dist/channels/whatsapp/index.d.ts",
|
|
50
55
|
"import": "./dist/channels/whatsapp/index.mjs",
|
|
@@ -58,7 +63,7 @@
|
|
|
58
63
|
],
|
|
59
64
|
"scripts": {
|
|
60
65
|
"dev": "bun --watch src/index.ts",
|
|
61
|
-
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:usage && bun run build:personas && bun run build:channels && bun run build:whatsapp && bun run build:bin && bun run build:client && bun run build:copy-client",
|
|
66
|
+
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:usage && bun run build:personas && bun run build:channels && bun run build:whatsapp && bun run build:flows && bun run build:bin && bun run build:client && bun run build:copy-client",
|
|
62
67
|
"build:clean": "rm -rf dist",
|
|
63
68
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
64
69
|
"build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.mjs --external:hono --external:openai --external:@libsql/client --external:jose --platform=node --target=node24",
|
|
@@ -68,6 +73,7 @@
|
|
|
68
73
|
"build:personas": "esbuild src/personas/index.ts --bundle --format=esm --outfile=dist/personas/index.mjs --platform=node --target=node24 && esbuild src/personas/index.ts --bundle --format=cjs --outfile=dist/personas/index.js --platform=node --target=node24",
|
|
69
74
|
"build:channels": "esbuild src/channels/index.ts --bundle --format=esm --outfile=dist/channels/index.mjs --external:hono --external:openai --external:@libsql/client --platform=node --target=node24 && esbuild src/channels/index.ts --bundle --format=cjs --outfile=dist/channels/index.js --external:hono --external:openai --external:@libsql/client --platform=node --target=node24",
|
|
70
75
|
"build:whatsapp": "esbuild src/channels/whatsapp/index.ts --bundle --format=esm --outfile=dist/channels/whatsapp/index.mjs --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24 && esbuild src/channels/whatsapp/index.ts --bundle --format=cjs --outfile=dist/channels/whatsapp/index.js --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24",
|
|
76
|
+
"build:flows": "esbuild src/flows/index.ts --bundle --format=esm --outfile=dist/flows/index.mjs --external:@libsql/client --external:openai --platform=node --target=node24 && esbuild src/flows/index.ts --bundle --format=cjs --outfile=dist/flows/index.js --external:@libsql/client --external:openai --platform=node --target=node24",
|
|
71
77
|
"build:bin": "esbuild bin/create-apikey.ts --bundle --format=cjs --outfile=dist/bin/create-apikey.js --external:jose --platform=node --target=node18 --banner:js='#!/usr/bin/env node' && esbuild bin/wa-pair.ts --bundle --format=cjs --outfile=dist/bin/wa-pair.js --external:@libsql/client --external:@whiskeysockets/baileys --external:qrcode-terminal --platform=node --target=node18 --banner:js='#!/usr/bin/env node'",
|
|
72
78
|
"build:client": "cd src/client && bun run build",
|
|
73
79
|
"build:copy-client": "mkdir -p dist/static && cp src/client/dist/chatter.js src/client/dist/chatter.css dist/static/",
|