@contractspec/example.ai-support-bot 1.57.0 → 1.58.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/.turbo/turbo-build.log +31 -30
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +15 -0
- package/dist/browser/docs/ai-support-bot.docblock.js +38 -0
- package/dist/browser/docs/index.js +38 -0
- package/dist/browser/example.js +33 -0
- package/dist/browser/index.js +113 -0
- package/dist/browser/setup.js +43 -0
- package/dist/docs/ai-support-bot.docblock.d.ts +2 -1
- package/dist/docs/ai-support-bot.docblock.d.ts.map +1 -0
- package/dist/docs/ai-support-bot.docblock.js +36 -26
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +39 -1
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +32 -43
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -4
- package/dist/node/docs/ai-support-bot.docblock.js +38 -0
- package/dist/node/docs/index.js +38 -0
- package/dist/node/example.js +33 -0
- package/dist/node/index.js +113 -0
- package/dist/node/setup.js +43 -0
- package/dist/setup.d.ts +1 -4
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +38 -39
- package/package.json +63 -26
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -30
- package/dist/docs/ai-support-bot.docblock.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/setup.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import "
|
|
1
|
+
// @bun
|
|
2
|
+
// src/docs/ai-support-bot.docblock.ts
|
|
3
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
4
|
+
var blocks = [
|
|
5
|
+
{
|
|
6
|
+
id: "docs.examples.ai-support-bot",
|
|
7
|
+
title: "AI Support Bot (example)",
|
|
8
|
+
summary: "Ticket classification + knowledge-grounded resolution + response drafting.",
|
|
9
|
+
kind: "reference",
|
|
10
|
+
visibility: "public",
|
|
11
|
+
route: "/docs/examples/ai-support-bot",
|
|
12
|
+
tags: ["support", "ai", "example"],
|
|
13
|
+
body: `## What this example shows
|
|
14
|
+
- Classify a ticket into a support category.
|
|
15
|
+
- Use a knowledge port to generate a grounded resolution.
|
|
16
|
+
- Draft a response (email body) from the resolution.
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
## Guardrails
|
|
19
|
+
- Avoid logging raw ticket bodies/PII; prefer structured summaries.
|
|
20
|
+
- Keep knowledge and ticket adapters explicit and testable.`
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "docs.examples.ai-support-bot.usage",
|
|
24
|
+
title: "AI Support Bot \u2014 Usage",
|
|
25
|
+
summary: "How to run the example and swap the knowledge adapter.",
|
|
26
|
+
kind: "usage",
|
|
27
|
+
visibility: "public",
|
|
28
|
+
route: "/docs/examples/ai-support-bot/usage",
|
|
29
|
+
tags: ["support", "usage"],
|
|
30
|
+
body: `## Usage
|
|
31
|
+
- Call \`runAiSupportBotExample()\`.
|
|
32
|
+
- Replace the \`knowledge.query\` implementation with a real knowledge service.
|
|
33
|
+
|
|
34
|
+
## Notes
|
|
35
|
+
- Keep outputs structured.
|
|
36
|
+
- Use policy gates before exposing drafted replies to end-users.`
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
registerDocBlocks(blocks);
|
|
40
|
+
// src/example.ts
|
|
41
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
42
|
+
var example = defineExample({
|
|
43
|
+
meta: {
|
|
44
|
+
key: "ai-support-bot",
|
|
45
|
+
version: "1.0.0",
|
|
46
|
+
title: "AI Support Bot",
|
|
47
|
+
description: "Classify and resolve a support ticket (with a drafted response) using the support-bot and knowledge libraries.",
|
|
48
|
+
kind: "script",
|
|
49
|
+
visibility: "public",
|
|
50
|
+
stability: "experimental",
|
|
51
|
+
owners: ["@platform.core"],
|
|
52
|
+
tags: ["support", "ai", "tickets", "knowledge"]
|
|
53
|
+
},
|
|
54
|
+
docs: {
|
|
55
|
+
rootDocId: "docs.examples.ai-support-bot",
|
|
56
|
+
usageDocId: "docs.examples.ai-support-bot.usage"
|
|
57
|
+
},
|
|
58
|
+
entrypoints: {
|
|
59
|
+
packageName: "@contractspec/example.ai-support-bot",
|
|
60
|
+
docs: "./docs"
|
|
61
|
+
},
|
|
62
|
+
surfaces: {
|
|
63
|
+
templates: true,
|
|
64
|
+
sandbox: { enabled: true, modes: ["markdown"] },
|
|
65
|
+
studio: { enabled: true, installable: true },
|
|
66
|
+
mcp: { enabled: true }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var example_default = example;
|
|
70
|
+
|
|
71
|
+
// src/setup.ts
|
|
72
|
+
import { TicketResolver } from "@contractspec/lib.support-bot/rag";
|
|
73
|
+
import { TicketClassifier } from "@contractspec/lib.support-bot/tickets";
|
|
74
|
+
import { AutoResponder } from "@contractspec/lib.support-bot/bot";
|
|
75
|
+
import { Logger, LogLevel } from "@contractspec/lib.logger";
|
|
76
|
+
var logger = new Logger({
|
|
77
|
+
level: LogLevel.DEBUG,
|
|
78
|
+
environment: "development",
|
|
79
|
+
enableColors: true
|
|
80
|
+
});
|
|
81
|
+
async function runAiSupportBotExample() {
|
|
82
|
+
const knowledge = {
|
|
83
|
+
async query(question) {
|
|
84
|
+
return {
|
|
85
|
+
answer: `The payout will retrigger automatically. (${question.slice(0, 40)}\u2026)`,
|
|
86
|
+
references: []
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const resolver = new TicketResolver({ knowledge });
|
|
91
|
+
const classifier = new TicketClassifier;
|
|
92
|
+
const responder = new AutoResponder;
|
|
93
|
+
const ticket = {
|
|
94
|
+
id: "TIC-42",
|
|
95
|
+
subject: "Payout failed",
|
|
96
|
+
body: "Hello, our supplier payout failed twice yesterday. Can you confirm status? It is urgent.",
|
|
97
|
+
channel: "email",
|
|
98
|
+
customerName: "Ivy",
|
|
99
|
+
metadata: { accountId: "acct_789" }
|
|
100
|
+
};
|
|
101
|
+
const classification = await classifier.classify(ticket);
|
|
102
|
+
const resolution = await resolver.resolve(ticket);
|
|
103
|
+
const draft = await responder.draft(ticket, resolution, classification);
|
|
104
|
+
logger.info("Support bot run completed", {
|
|
105
|
+
ticketId: ticket.id,
|
|
106
|
+
classification,
|
|
107
|
+
resolution,
|
|
108
|
+
emailDraft: { subject: draft.subject, body: draft.body }
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
runAiSupportBotExample,
|
|
113
|
+
example_default as example
|
|
114
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/docs/ai-support-bot.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.ai-support-bot",
|
|
6
|
+
title: "AI Support Bot (example)",
|
|
7
|
+
summary: "Ticket classification + knowledge-grounded resolution + response drafting.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/ai-support-bot",
|
|
11
|
+
tags: ["support", "ai", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Classify a ticket into a support category.
|
|
14
|
+
- Use a knowledge port to generate a grounded resolution.
|
|
15
|
+
- Draft a response (email body) from the resolution.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Avoid logging raw ticket bodies/PII; prefer structured summaries.
|
|
19
|
+
- Keep knowledge and ticket adapters explicit and testable.`
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "docs.examples.ai-support-bot.usage",
|
|
23
|
+
title: "AI Support Bot — Usage",
|
|
24
|
+
summary: "How to run the example and swap the knowledge adapter.",
|
|
25
|
+
kind: "usage",
|
|
26
|
+
visibility: "public",
|
|
27
|
+
route: "/docs/examples/ai-support-bot/usage",
|
|
28
|
+
tags: ["support", "usage"],
|
|
29
|
+
body: `## Usage
|
|
30
|
+
- Call \`runAiSupportBotExample()\`.
|
|
31
|
+
- Replace the \`knowledge.query\` implementation with a real knowledge service.
|
|
32
|
+
|
|
33
|
+
## Notes
|
|
34
|
+
- Keep outputs structured.
|
|
35
|
+
- Use policy gates before exposing drafted replies to end-users.`
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
registerDocBlocks(blocks);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/docs/ai-support-bot.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.ai-support-bot",
|
|
6
|
+
title: "AI Support Bot (example)",
|
|
7
|
+
summary: "Ticket classification + knowledge-grounded resolution + response drafting.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/ai-support-bot",
|
|
11
|
+
tags: ["support", "ai", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Classify a ticket into a support category.
|
|
14
|
+
- Use a knowledge port to generate a grounded resolution.
|
|
15
|
+
- Draft a response (email body) from the resolution.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Avoid logging raw ticket bodies/PII; prefer structured summaries.
|
|
19
|
+
- Keep knowledge and ticket adapters explicit and testable.`
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "docs.examples.ai-support-bot.usage",
|
|
23
|
+
title: "AI Support Bot — Usage",
|
|
24
|
+
summary: "How to run the example and swap the knowledge adapter.",
|
|
25
|
+
kind: "usage",
|
|
26
|
+
visibility: "public",
|
|
27
|
+
route: "/docs/examples/ai-support-bot/usage",
|
|
28
|
+
tags: ["support", "usage"],
|
|
29
|
+
body: `## Usage
|
|
30
|
+
- Call \`runAiSupportBotExample()\`.
|
|
31
|
+
- Replace the \`knowledge.query\` implementation with a real knowledge service.
|
|
32
|
+
|
|
33
|
+
## Notes
|
|
34
|
+
- Keep outputs structured.
|
|
35
|
+
- Use policy gates before exposing drafted replies to end-users.`
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
registerDocBlocks(blocks);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/example.ts
|
|
2
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
3
|
+
var example = defineExample({
|
|
4
|
+
meta: {
|
|
5
|
+
key: "ai-support-bot",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
title: "AI Support Bot",
|
|
8
|
+
description: "Classify and resolve a support ticket (with a drafted response) using the support-bot and knowledge libraries.",
|
|
9
|
+
kind: "script",
|
|
10
|
+
visibility: "public",
|
|
11
|
+
stability: "experimental",
|
|
12
|
+
owners: ["@platform.core"],
|
|
13
|
+
tags: ["support", "ai", "tickets", "knowledge"]
|
|
14
|
+
},
|
|
15
|
+
docs: {
|
|
16
|
+
rootDocId: "docs.examples.ai-support-bot",
|
|
17
|
+
usageDocId: "docs.examples.ai-support-bot.usage"
|
|
18
|
+
},
|
|
19
|
+
entrypoints: {
|
|
20
|
+
packageName: "@contractspec/example.ai-support-bot",
|
|
21
|
+
docs: "./docs"
|
|
22
|
+
},
|
|
23
|
+
surfaces: {
|
|
24
|
+
templates: true,
|
|
25
|
+
sandbox: { enabled: true, modes: ["markdown"] },
|
|
26
|
+
studio: { enabled: true, installable: true },
|
|
27
|
+
mcp: { enabled: true }
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var example_default = example;
|
|
31
|
+
export {
|
|
32
|
+
example_default as default
|
|
33
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/docs/ai-support-bot.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.ai-support-bot",
|
|
6
|
+
title: "AI Support Bot (example)",
|
|
7
|
+
summary: "Ticket classification + knowledge-grounded resolution + response drafting.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/ai-support-bot",
|
|
11
|
+
tags: ["support", "ai", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Classify a ticket into a support category.
|
|
14
|
+
- Use a knowledge port to generate a grounded resolution.
|
|
15
|
+
- Draft a response (email body) from the resolution.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Avoid logging raw ticket bodies/PII; prefer structured summaries.
|
|
19
|
+
- Keep knowledge and ticket adapters explicit and testable.`
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "docs.examples.ai-support-bot.usage",
|
|
23
|
+
title: "AI Support Bot — Usage",
|
|
24
|
+
summary: "How to run the example and swap the knowledge adapter.",
|
|
25
|
+
kind: "usage",
|
|
26
|
+
visibility: "public",
|
|
27
|
+
route: "/docs/examples/ai-support-bot/usage",
|
|
28
|
+
tags: ["support", "usage"],
|
|
29
|
+
body: `## Usage
|
|
30
|
+
- Call \`runAiSupportBotExample()\`.
|
|
31
|
+
- Replace the \`knowledge.query\` implementation with a real knowledge service.
|
|
32
|
+
|
|
33
|
+
## Notes
|
|
34
|
+
- Keep outputs structured.
|
|
35
|
+
- Use policy gates before exposing drafted replies to end-users.`
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
registerDocBlocks(blocks);
|
|
39
|
+
// src/example.ts
|
|
40
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
41
|
+
var example = defineExample({
|
|
42
|
+
meta: {
|
|
43
|
+
key: "ai-support-bot",
|
|
44
|
+
version: "1.0.0",
|
|
45
|
+
title: "AI Support Bot",
|
|
46
|
+
description: "Classify and resolve a support ticket (with a drafted response) using the support-bot and knowledge libraries.",
|
|
47
|
+
kind: "script",
|
|
48
|
+
visibility: "public",
|
|
49
|
+
stability: "experimental",
|
|
50
|
+
owners: ["@platform.core"],
|
|
51
|
+
tags: ["support", "ai", "tickets", "knowledge"]
|
|
52
|
+
},
|
|
53
|
+
docs: {
|
|
54
|
+
rootDocId: "docs.examples.ai-support-bot",
|
|
55
|
+
usageDocId: "docs.examples.ai-support-bot.usage"
|
|
56
|
+
},
|
|
57
|
+
entrypoints: {
|
|
58
|
+
packageName: "@contractspec/example.ai-support-bot",
|
|
59
|
+
docs: "./docs"
|
|
60
|
+
},
|
|
61
|
+
surfaces: {
|
|
62
|
+
templates: true,
|
|
63
|
+
sandbox: { enabled: true, modes: ["markdown"] },
|
|
64
|
+
studio: { enabled: true, installable: true },
|
|
65
|
+
mcp: { enabled: true }
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
var example_default = example;
|
|
69
|
+
|
|
70
|
+
// src/setup.ts
|
|
71
|
+
import { TicketResolver } from "@contractspec/lib.support-bot/rag";
|
|
72
|
+
import { TicketClassifier } from "@contractspec/lib.support-bot/tickets";
|
|
73
|
+
import { AutoResponder } from "@contractspec/lib.support-bot/bot";
|
|
74
|
+
import { Logger, LogLevel } from "@contractspec/lib.logger";
|
|
75
|
+
var logger = new Logger({
|
|
76
|
+
level: LogLevel.DEBUG,
|
|
77
|
+
environment: "development",
|
|
78
|
+
enableColors: true
|
|
79
|
+
});
|
|
80
|
+
async function runAiSupportBotExample() {
|
|
81
|
+
const knowledge = {
|
|
82
|
+
async query(question) {
|
|
83
|
+
return {
|
|
84
|
+
answer: `The payout will retrigger automatically. (${question.slice(0, 40)}…)`,
|
|
85
|
+
references: []
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const resolver = new TicketResolver({ knowledge });
|
|
90
|
+
const classifier = new TicketClassifier;
|
|
91
|
+
const responder = new AutoResponder;
|
|
92
|
+
const ticket = {
|
|
93
|
+
id: "TIC-42",
|
|
94
|
+
subject: "Payout failed",
|
|
95
|
+
body: "Hello, our supplier payout failed twice yesterday. Can you confirm status? It is urgent.",
|
|
96
|
+
channel: "email",
|
|
97
|
+
customerName: "Ivy",
|
|
98
|
+
metadata: { accountId: "acct_789" }
|
|
99
|
+
};
|
|
100
|
+
const classification = await classifier.classify(ticket);
|
|
101
|
+
const resolution = await resolver.resolve(ticket);
|
|
102
|
+
const draft = await responder.draft(ticket, resolution, classification);
|
|
103
|
+
logger.info("Support bot run completed", {
|
|
104
|
+
ticketId: ticket.id,
|
|
105
|
+
classification,
|
|
106
|
+
resolution,
|
|
107
|
+
emailDraft: { subject: draft.subject, body: draft.body }
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
runAiSupportBotExample,
|
|
112
|
+
example_default as example
|
|
113
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/setup.ts
|
|
2
|
+
import { TicketResolver } from "@contractspec/lib.support-bot/rag";
|
|
3
|
+
import { TicketClassifier } from "@contractspec/lib.support-bot/tickets";
|
|
4
|
+
import { AutoResponder } from "@contractspec/lib.support-bot/bot";
|
|
5
|
+
import { Logger, LogLevel } from "@contractspec/lib.logger";
|
|
6
|
+
var logger = new Logger({
|
|
7
|
+
level: LogLevel.DEBUG,
|
|
8
|
+
environment: "development",
|
|
9
|
+
enableColors: true
|
|
10
|
+
});
|
|
11
|
+
async function runAiSupportBotExample() {
|
|
12
|
+
const knowledge = {
|
|
13
|
+
async query(question) {
|
|
14
|
+
return {
|
|
15
|
+
answer: `The payout will retrigger automatically. (${question.slice(0, 40)}…)`,
|
|
16
|
+
references: []
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const resolver = new TicketResolver({ knowledge });
|
|
21
|
+
const classifier = new TicketClassifier;
|
|
22
|
+
const responder = new AutoResponder;
|
|
23
|
+
const ticket = {
|
|
24
|
+
id: "TIC-42",
|
|
25
|
+
subject: "Payout failed",
|
|
26
|
+
body: "Hello, our supplier payout failed twice yesterday. Can you confirm status? It is urgent.",
|
|
27
|
+
channel: "email",
|
|
28
|
+
customerName: "Ivy",
|
|
29
|
+
metadata: { accountId: "acct_789" }
|
|
30
|
+
};
|
|
31
|
+
const classification = await classifier.classify(ticket);
|
|
32
|
+
const resolution = await resolver.resolve(ticket);
|
|
33
|
+
const draft = await responder.draft(ticket, resolution, classification);
|
|
34
|
+
logger.info("Support bot run completed", {
|
|
35
|
+
ticketId: ticket.id,
|
|
36
|
+
classification,
|
|
37
|
+
resolution,
|
|
38
|
+
emailDraft: { subject: draft.subject, body: draft.body }
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
runAiSupportBotExample
|
|
43
|
+
};
|
package/dist/setup.d.ts
CHANGED
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAeA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiC5D"}
|
package/dist/setup.js
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/setup.ts
|
|
1
3
|
import { TicketResolver } from "@contractspec/lib.support-bot/rag";
|
|
2
4
|
import { TicketClassifier } from "@contractspec/lib.support-bot/tickets";
|
|
3
5
|
import { AutoResponder } from "@contractspec/lib.support-bot/bot";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
environment: process.env.NODE_ENV || "development",
|
|
10
|
-
enableColors: process.env.NODE_ENV !== "production"
|
|
6
|
+
import { Logger, LogLevel } from "@contractspec/lib.logger";
|
|
7
|
+
var logger = new Logger({
|
|
8
|
+
level: LogLevel.DEBUG,
|
|
9
|
+
environment: "development",
|
|
10
|
+
enableColors: true
|
|
11
11
|
});
|
|
12
12
|
async function runAiSupportBotExample() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
const knowledge = {
|
|
14
|
+
async query(question) {
|
|
15
|
+
return {
|
|
16
|
+
answer: `The payout will retrigger automatically. (${question.slice(0, 40)}\u2026)`,
|
|
17
|
+
references: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const resolver = new TicketResolver({ knowledge });
|
|
22
|
+
const classifier = new TicketClassifier;
|
|
23
|
+
const responder = new AutoResponder;
|
|
24
|
+
const ticket = {
|
|
25
|
+
id: "TIC-42",
|
|
26
|
+
subject: "Payout failed",
|
|
27
|
+
body: "Hello, our supplier payout failed twice yesterday. Can you confirm status? It is urgent.",
|
|
28
|
+
channel: "email",
|
|
29
|
+
customerName: "Ivy",
|
|
30
|
+
metadata: { accountId: "acct_789" }
|
|
31
|
+
};
|
|
32
|
+
const classification = await classifier.classify(ticket);
|
|
33
|
+
const resolution = await resolver.resolve(ticket);
|
|
34
|
+
const draft = await responder.draft(ticket, resolution, classification);
|
|
35
|
+
logger.info("Support bot run completed", {
|
|
36
|
+
ticketId: ticket.id,
|
|
37
|
+
classification,
|
|
38
|
+
resolution,
|
|
39
|
+
emailDraft: { subject: draft.subject, body: draft.body }
|
|
40
|
+
});
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//# sourceMappingURL=setup.js.map
|
|
42
|
+
export {
|
|
43
|
+
runAiSupportBotExample
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,51 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/example.ai-support-bot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0",
|
|
4
4
|
"description": "AI support bot example: classify and resolve a support ticket using @contractspec/lib.support-bot.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
9
|
-
"./docs": "./
|
|
10
|
-
"./docs/ai-support-bot.docblock": "./
|
|
11
|
-
"./
|
|
12
|
-
"./
|
|
13
|
-
"
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./docs": "./src/docs/index.ts",
|
|
10
|
+
"./docs/ai-support-bot.docblock": "./src/docs/ai-support-bot.docblock.ts",
|
|
11
|
+
"./docs/index": "./src/docs/index.ts",
|
|
12
|
+
"./example": "./src/example.ts",
|
|
13
|
+
"./setup": "./src/setup.ts"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
17
17
|
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
18
|
-
"build": "bun build:
|
|
19
|
-
"build:bundle": "
|
|
20
|
-
"build:types": "
|
|
21
|
-
"dev": "bun
|
|
18
|
+
"build": "bun run prebuild && bun run build:bundle && bun run build:types",
|
|
19
|
+
"build:bundle": "contractspec-bun-build transpile",
|
|
20
|
+
"build:types": "contractspec-bun-build types",
|
|
21
|
+
"dev": "contractspec-bun-build dev",
|
|
22
22
|
"clean": "rimraf dist .turbo",
|
|
23
23
|
"lint": "bun lint:fix",
|
|
24
24
|
"lint:fix": "eslint src --fix",
|
|
25
25
|
"lint:check": "eslint src",
|
|
26
|
-
"test": "bun test"
|
|
26
|
+
"test": "bun test",
|
|
27
|
+
"prebuild": "contractspec-bun-build prebuild",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"@contractspec/lib.support-bot": "1.
|
|
30
|
-
"@contractspec/lib.knowledge": "1.
|
|
31
|
-
"@contractspec/lib.contracts": "1.
|
|
32
|
-
"@contractspec/lib.logger": "1.
|
|
31
|
+
"@contractspec/lib.support-bot": "1.58.0",
|
|
32
|
+
"@contractspec/lib.knowledge": "1.58.0",
|
|
33
|
+
"@contractspec/lib.contracts": "1.58.0",
|
|
34
|
+
"@contractspec/lib.logger": "1.58.0"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"@contractspec/tool.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"typescript": "^5.9.3"
|
|
37
|
+
"@contractspec/tool.typescript": "1.58.0",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"@contractspec/tool.bun": "1.57.0"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public",
|
|
42
43
|
"exports": {
|
|
43
|
-
".":
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"bun": "./dist/index.js",
|
|
47
|
+
"node": "./dist/node/index.mjs",
|
|
48
|
+
"browser": "./dist/browser/index.js",
|
|
49
|
+
"default": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./docs": {
|
|
52
|
+
"types": "./dist/docs/index.d.ts",
|
|
53
|
+
"bun": "./dist/docs/index.js",
|
|
54
|
+
"node": "./dist/node/docs/index.mjs",
|
|
55
|
+
"browser": "./dist/browser/docs/index.js",
|
|
56
|
+
"default": "./dist/docs/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./docs/ai-support-bot.docblock": {
|
|
59
|
+
"types": "./dist/docs/ai-support-bot.docblock.d.ts",
|
|
60
|
+
"bun": "./dist/docs/ai-support-bot.docblock.js",
|
|
61
|
+
"node": "./dist/node/docs/ai-support-bot.docblock.mjs",
|
|
62
|
+
"browser": "./dist/browser/docs/ai-support-bot.docblock.js",
|
|
63
|
+
"default": "./dist/docs/ai-support-bot.docblock.js"
|
|
64
|
+
},
|
|
65
|
+
"./docs/index": {
|
|
66
|
+
"types": "./dist/docs/index.d.ts",
|
|
67
|
+
"bun": "./dist/docs/index.js",
|
|
68
|
+
"node": "./dist/node/docs/index.mjs",
|
|
69
|
+
"browser": "./dist/browser/docs/index.js",
|
|
70
|
+
"default": "./dist/docs/index.js"
|
|
71
|
+
},
|
|
72
|
+
"./example": {
|
|
73
|
+
"types": "./dist/example.d.ts",
|
|
74
|
+
"bun": "./dist/example.js",
|
|
75
|
+
"node": "./dist/node/example.mjs",
|
|
76
|
+
"browser": "./dist/browser/example.js",
|
|
77
|
+
"default": "./dist/example.js"
|
|
78
|
+
},
|
|
79
|
+
"./setup": {
|
|
80
|
+
"types": "./dist/setup.d.ts",
|
|
81
|
+
"bun": "./dist/setup.js",
|
|
82
|
+
"node": "./dist/node/setup.mjs",
|
|
83
|
+
"browser": "./dist/browser/setup.js",
|
|
84
|
+
"default": "./dist/setup.js"
|
|
85
|
+
}
|
|
49
86
|
},
|
|
50
87
|
"registry": "https://registry.npmjs.org/"
|
|
51
88
|
},
|
package/tsdown.config.js
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
$ tsdown
|
|
2
|
-
[34mℹ[39m tsdown [2mv0.20.3[22m powered by rolldown [2mv1.0.0-rc.3[22m
|
|
3
|
-
[34mℹ[39m config file: [4m/home/runner/work/contractspec/contractspec/packages/examples/ai-support-bot/tsdown.config.js[24m
|
|
4
|
-
[34mℹ[39m entry: [34msrc/example.ts, src/index.ts, src/setup.ts, src/docs/ai-support-bot.docblock.ts, src/docs/index.ts[39m
|
|
5
|
-
[34mℹ[39m target: [34mesnext[39m
|
|
6
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
7
|
-
[34mℹ[39m Build start
|
|
8
|
-
[34mℹ[39m Cleaning 16 files
|
|
9
|
-
[34mℹ[39m [2mdist/[22m[1msetup.js[22m [2m1.53 kB[22m [2m│ gzip: 0.75 kB[22m
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/ai-support-bot.docblock.js[22m [2m1.35 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mexample.js[22m [2m0.96 kB[22m [2m│ gzip: 0.51 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m0.16 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.04 kB[22m [2m│ gzip: 0.06 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22msetup.js.map [2m2.68 kB[22m [2m│ gzip: 1.18 kB[22m
|
|
15
|
-
[34mℹ[39m [2mdist/[22mdocs/ai-support-bot.docblock.js.map [2m1.84 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
16
|
-
[34mℹ[39m [2mdist/[22mexample.js.map [2m1.43 kB[22m [2m│ gzip: 0.70 kB[22m
|
|
17
|
-
[34mℹ[39m [2mdist/[22mexample.d.ts.map [2m0.13 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
18
|
-
[34mℹ[39m [2mdist/[22msetup.d.ts.map [2m0.12 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22m[32m[1mexample.d.ts[22m[39m [2m0.25 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22m[32m[1msetup.d.ts[22m[39m [2m0.17 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
21
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m0.13 kB[22m [2m│ gzip: 0.09 kB[22m
|
|
22
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/ai-support-bot.docblock.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
23
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/index.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
24
|
-
[34mℹ[39m 15 files, total: 10.80 kB
|
|
25
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugins. Here is a breakdown:
|
|
26
|
-
- tsdown:external (66%)
|
|
27
|
-
- rolldown-plugin-dts:generate (33%)
|
|
28
|
-
See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
29
|
-
|
|
30
|
-
[32m✔[39m Build complete in [32m16353ms[39m
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-support-bot.docblock.js","names":[],"sources":["../../src/docs/ai-support-bot.docblock.ts"],"sourcesContent":["import type { DocBlock } from '@contractspec/lib.contracts/docs';\nimport { registerDocBlocks } from '@contractspec/lib.contracts/docs';\n\nconst blocks: DocBlock[] = [\n {\n id: 'docs.examples.ai-support-bot',\n title: 'AI Support Bot (example)',\n summary:\n 'Ticket classification + knowledge-grounded resolution + response drafting.',\n kind: 'reference',\n visibility: 'public',\n route: '/docs/examples/ai-support-bot',\n tags: ['support', 'ai', 'example'],\n 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.`,\n },\n {\n id: 'docs.examples.ai-support-bot.usage',\n title: 'AI Support Bot — Usage',\n summary: 'How to run the example and swap the knowledge adapter.',\n kind: 'usage',\n visibility: 'public',\n route: '/docs/examples/ai-support-bot/usage',\n tags: ['support', 'usage'],\n 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.`,\n },\n];\n\nregisterDocBlocks(blocks);\n"],"mappings":";;;AA2BA,kBAxB2B,CACzB;CACE,IAAI;CACJ,OAAO;CACP,SACE;CACF,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM;EAAC;EAAW;EAAM;EAAU;CAClC,MAAM;CACP,EACD;CACE,IAAI;CACJ,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM,CAAC,WAAW,QAAQ;CAC1B,MAAM;CACP,CACF,CAEwB"}
|
package/dist/example.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example.js","names":[],"sources":["../src/example.ts"],"sourcesContent":["import { defineExample } from '@contractspec/lib.contracts';\n\nconst example = defineExample({\n meta: {\n key: 'ai-support-bot',\n version: '1.0.0',\n title: 'AI Support Bot',\n description:\n 'Classify and resolve a support ticket (with a drafted response) using the support-bot and knowledge libraries.',\n kind: 'script',\n visibility: 'public',\n stability: 'experimental',\n owners: ['@platform.core'],\n tags: ['support', 'ai', 'tickets', 'knowledge'],\n },\n docs: {\n rootDocId: 'docs.examples.ai-support-bot',\n usageDocId: 'docs.examples.ai-support-bot.usage',\n },\n entrypoints: {\n packageName: '@contractspec/example.ai-support-bot',\n docs: './docs',\n },\n surfaces: {\n templates: true,\n sandbox: { enabled: true, modes: ['markdown'] },\n studio: { enabled: true, installable: true },\n mcp: { enabled: true },\n },\n});\n\nexport default example;\n"],"mappings":";;;AAEA,MAAM,UAAU,cAAc;CAC5B,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,aACE;EACF,MAAM;EACN,YAAY;EACZ,WAAW;EACX,QAAQ,CAAC,iBAAiB;EAC1B,MAAM;GAAC;GAAW;GAAM;GAAW;GAAY;EAChD;CACD,MAAM;EACJ,WAAW;EACX,YAAY;EACb;CACD,aAAa;EACX,aAAa;EACb,MAAM;EACP;CACD,UAAU;EACR,WAAW;EACX,SAAS;GAAE,SAAS;GAAM,OAAO,CAAC,WAAW;GAAE;EAC/C,QAAQ;GAAE,SAAS;GAAM,aAAa;GAAM;EAC5C,KAAK,EAAE,SAAS,MAAM;EACvB;CACF,CAAC"}
|