@contractspec/example.ai-support-bot 0.0.0-canary-20260113170453
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/.turbo/turbo-build$colon$bundle.log +25 -0
- package/.turbo/turbo-build.log +26 -0
- package/CHANGELOG.md +379 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/docs/ai-support-bot.docblock.d.ts +1 -0
- package/dist/docs/ai-support-bot.docblock.js +29 -0
- package/dist/docs/ai-support-bot.docblock.js.map +1 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +46 -0
- package/dist/example.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/setup.d.ts +5 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +45 -0
- package/dist/setup.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +59 -0
- package/setup.ts +8 -0
- package/src/docs/ai-support-bot.docblock.ts +28 -0
- package/src/docs/index.ts +1 -0
- package/src/example.ts +32 -0
- package/src/index.ts +3 -0
- package/src/setup.ts +49 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +6 -0
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractspec/example.ai-support-bot",
|
|
3
|
+
"version": "0.0.0-canary-20260113170453",
|
|
4
|
+
"description": "AI support bot example: classify and resolve a support ticket using @contractspec/lib.support-bot.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./docs": "./dist/docs/index.js",
|
|
10
|
+
"./docs/ai-support-bot.docblock": "./dist/docs/ai-support-bot.docblock.js",
|
|
11
|
+
"./example": "./dist/example.js",
|
|
12
|
+
"./setup": "./dist/setup.js",
|
|
13
|
+
"./*": "./*"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
17
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
18
|
+
"build": "bun build:types && bun build:bundle",
|
|
19
|
+
"build:bundle": "tsdown",
|
|
20
|
+
"build:types": "tsc --noEmit",
|
|
21
|
+
"dev": "bun build:bundle --watch",
|
|
22
|
+
"clean": "rimraf dist .turbo",
|
|
23
|
+
"lint": "bun lint:fix",
|
|
24
|
+
"lint:fix": "eslint src --fix",
|
|
25
|
+
"lint:check": "eslint src",
|
|
26
|
+
"test": "bun test"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@contractspec/lib.support-bot": "0.0.0-canary-20260113170453",
|
|
30
|
+
"@contractspec/lib.knowledge": "0.0.0-canary-20260113170453",
|
|
31
|
+
"@contractspec/lib.contracts": "0.0.0-canary-20260113170453",
|
|
32
|
+
"@contractspec/lib.logger": "0.0.0-canary-20260113170453"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@contractspec/tool.tsdown": "0.0.0-canary-20260113170453",
|
|
36
|
+
"@contractspec/tool.typescript": "0.0.0-canary-20260113170453",
|
|
37
|
+
"tsdown": "^0.19.0",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": "./dist/index.js",
|
|
44
|
+
"./docs": "./dist/docs/index.js",
|
|
45
|
+
"./docs/ai-support-bot.docblock": "./dist/docs/ai-support-bot.docblock.js",
|
|
46
|
+
"./example": "./dist/example.js",
|
|
47
|
+
"./setup": "./dist/setup.js",
|
|
48
|
+
"./*": "./*"
|
|
49
|
+
},
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
},
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
56
|
+
"directory": "packages/examples/ai-support-bot"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://contractspec.io"
|
|
59
|
+
}
|
package/setup.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DocBlock } from '@contractspec/lib.contracts/docs';
|
|
2
|
+
import { registerDocBlocks } from '@contractspec/lib.contracts/docs';
|
|
3
|
+
|
|
4
|
+
const blocks: DocBlock[] = [
|
|
5
|
+
{
|
|
6
|
+
id: 'docs.examples.ai-support-bot',
|
|
7
|
+
title: 'AI Support Bot (example)',
|
|
8
|
+
summary:
|
|
9
|
+
'Ticket classification + knowledge-grounded resolution + response drafting.',
|
|
10
|
+
kind: 'reference',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
route: '/docs/examples/ai-support-bot',
|
|
13
|
+
tags: ['support', 'ai', 'example'],
|
|
14
|
+
body: `## What this example shows\n- Classify a ticket into a support category.\n- Use a knowledge port to generate a grounded resolution.\n- Draft a response (email body) from the resolution.\n\n## Guardrails\n- Avoid logging raw ticket bodies/PII; prefer structured summaries.\n- Keep knowledge and ticket adapters explicit and testable.`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'docs.examples.ai-support-bot.usage',
|
|
18
|
+
title: 'AI Support Bot — Usage',
|
|
19
|
+
summary: 'How to run the example and swap the knowledge adapter.',
|
|
20
|
+
kind: 'usage',
|
|
21
|
+
visibility: 'public',
|
|
22
|
+
route: '/docs/examples/ai-support-bot/usage',
|
|
23
|
+
tags: ['support', 'usage'],
|
|
24
|
+
body: `## Usage\n- Call \`runAiSupportBotExample()\`.\n- Replace the \`knowledge.query\` implementation with a real knowledge service.\n\n## Notes\n- Keep outputs structured.\n- Use policy gates before exposing drafted replies to end-users.`,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
registerDocBlocks(blocks);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './ai-support-bot.docblock';
|
package/src/example.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineExample } from '@contractspec/lib.contracts';
|
|
2
|
+
|
|
3
|
+
const example = defineExample({
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'ai-support-bot',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
title: 'AI Support Bot',
|
|
8
|
+
description:
|
|
9
|
+
'Classify and resolve a support ticket (with a drafted response) using the support-bot and knowledge libraries.',
|
|
10
|
+
kind: 'script',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
stability: 'experimental',
|
|
13
|
+
owners: ['@platform.core'],
|
|
14
|
+
tags: ['support', 'ai', 'tickets', 'knowledge'],
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
rootDocId: 'docs.examples.ai-support-bot',
|
|
18
|
+
usageDocId: 'docs.examples.ai-support-bot.usage',
|
|
19
|
+
},
|
|
20
|
+
entrypoints: {
|
|
21
|
+
packageName: '@contractspec/example.ai-support-bot',
|
|
22
|
+
docs: './docs',
|
|
23
|
+
},
|
|
24
|
+
surfaces: {
|
|
25
|
+
templates: true,
|
|
26
|
+
sandbox: { enabled: true, modes: ['markdown'] },
|
|
27
|
+
studio: { enabled: true, installable: true },
|
|
28
|
+
mcp: { enabled: true },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export default example;
|
package/src/index.ts
ADDED
package/src/setup.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TicketResolver } from '@contractspec/lib.support-bot/rag';
|
|
2
|
+
import { TicketClassifier } from '@contractspec/lib.support-bot/tickets';
|
|
3
|
+
import { AutoResponder } from '@contractspec/lib.support-bot/bot';
|
|
4
|
+
import type { KnowledgeAnswer } from '@contractspec/lib.knowledge/query/service';
|
|
5
|
+
import type { SupportTicket } from '@contractspec/lib.support-bot/types';
|
|
6
|
+
import { Logger, LogLevel } from '@contractspec/lib.logger';
|
|
7
|
+
import type { LoggerConfig } from '@contractspec/lib.logger/types';
|
|
8
|
+
|
|
9
|
+
const logger = new Logger({
|
|
10
|
+
level: process.env.NODE_ENV === 'production' ? LogLevel.INFO : LogLevel.DEBUG,
|
|
11
|
+
environment:
|
|
12
|
+
(process.env.NODE_ENV as LoggerConfig['environment']) || 'development',
|
|
13
|
+
enableColors: process.env.NODE_ENV !== 'production',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export async function runAiSupportBotExample(): Promise<void> {
|
|
17
|
+
const knowledge = {
|
|
18
|
+
async query(question: string): Promise<KnowledgeAnswer> {
|
|
19
|
+
return {
|
|
20
|
+
answer: `The payout will retrigger automatically. (${question.slice(0, 40)}…)`,
|
|
21
|
+
references: [],
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const resolver = new TicketResolver({ knowledge });
|
|
27
|
+
const classifier = new TicketClassifier();
|
|
28
|
+
const responder = new AutoResponder();
|
|
29
|
+
|
|
30
|
+
const ticket: SupportTicket = {
|
|
31
|
+
id: 'TIC-42',
|
|
32
|
+
subject: 'Payout failed',
|
|
33
|
+
body: 'Hello, our supplier payout failed twice yesterday. Can you confirm status? It is urgent.',
|
|
34
|
+
channel: 'email',
|
|
35
|
+
customerName: 'Ivy',
|
|
36
|
+
metadata: { accountId: 'acct_789' },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const classification = await classifier.classify(ticket);
|
|
40
|
+
const resolution = await resolver.resolve(ticket);
|
|
41
|
+
const draft = await responder.draft(ticket, resolution, classification);
|
|
42
|
+
|
|
43
|
+
logger.info('Support bot run completed', {
|
|
44
|
+
ticketId: ticket.id,
|
|
45
|
+
classification,
|
|
46
|
+
resolution,
|
|
47
|
+
emailDraft: { subject: draft.subject, body: draft.body },
|
|
48
|
+
});
|
|
49
|
+
}
|