@contractspec/lib.support-bot 1.44.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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/ai-agent/src/agent/agent-factory.d.ts +7 -0
- package/dist/ai-agent/src/agent/contract-spec-agent.d.ts +5 -0
- package/dist/ai-agent/src/agent/index.d.ts +2 -0
- package/dist/ai-agent/src/approval/index.d.ts +1 -0
- package/dist/ai-agent/src/approval/workflow.d.ts +1 -0
- package/dist/ai-agent/src/index.d.ts +11 -0
- package/dist/ai-agent/src/knowledge/index.d.ts +1 -0
- package/dist/ai-agent/src/knowledge/injector.d.ts +1 -0
- package/dist/ai-agent/src/schema/index.d.ts +2 -0
- package/dist/ai-agent/src/schema/json-schema-to-zod.d.ts +1 -0
- package/dist/ai-agent/src/schema/schema-output.d.ts +2 -0
- package/dist/ai-agent/src/session/index.d.ts +1 -0
- package/dist/ai-agent/src/session/store.d.ts +2 -0
- package/dist/ai-agent/src/spec/index.d.ts +2 -0
- package/dist/ai-agent/src/spec/registry.d.ts +1 -0
- package/dist/ai-agent/src/spec/spec.d.ts +115 -0
- package/dist/ai-agent/src/spec/spec.d.ts.map +1 -0
- package/dist/ai-agent/src/telemetry/adapter.d.ts +1 -0
- package/dist/ai-agent/src/telemetry/index.d.ts +1 -0
- package/dist/ai-agent/src/tools/index.d.ts +4 -0
- package/dist/ai-agent/src/tools/knowledge-tool.d.ts +2 -0
- package/dist/ai-agent/src/tools/mcp-client.d.ts +1 -0
- package/dist/ai-agent/src/tools/mcp-server.d.ts +3 -0
- package/dist/ai-agent/src/tools/tool-adapter.d.ts +3 -0
- package/dist/ai-agent/src/types.d.ts +1 -0
- package/dist/bot/auto-responder.d.ts +26 -0
- package/dist/bot/auto-responder.d.ts.map +1 -0
- package/dist/bot/auto-responder.js +84 -0
- package/dist/bot/auto-responder.js.map +1 -0
- package/dist/bot/feedback-loop.d.ts +20 -0
- package/dist/bot/feedback-loop.d.ts.map +1 -0
- package/dist/bot/feedback-loop.js +35 -0
- package/dist/bot/feedback-loop.js.map +1 -0
- package/dist/bot/index.d.ts +4 -0
- package/dist/bot/index.js +5 -0
- package/dist/bot/tools.d.ts +15 -0
- package/dist/bot/tools.d.ts.map +1 -0
- package/dist/bot/tools.js +137 -0
- package/dist/bot/tools.js.map +1 -0
- package/dist/contracts/src/docs/accessibility_wcag_compliance_specs.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/index.d.ts +25 -0
- package/dist/contracts/src/docs/presentations.d.ts +2 -0
- package/dist/contracts/src/docs/registry.d.ts +10 -0
- package/dist/contracts/src/docs/registry.d.ts.map +1 -0
- package/dist/contracts/src/docs/tech/auth/better-auth-nextjs.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/contracts/openapi-export.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/contracts/openapi-import.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/lifecycle-stage-system.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/llm/llm-integration.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/mcp-endpoints.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/presentation-runtime.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/schema/README.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/learning-events.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/learning-journeys.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/platform-admin-panel.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/project-access-teams.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/project-routing.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/sandbox-unlogged.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/team-invitations.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/workspace-ops.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/studio/workspaces.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/telemetry-ingest.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/templates/runtime.docblock.d.ts +1 -0
- package/dist/contracts/src/docs/tech/vscode-extension.docblock.d.ts +1 -0
- package/dist/contracts/src/integrations/providers/llm.d.ts +83 -0
- package/dist/contracts/src/integrations/providers/llm.d.ts.map +1 -0
- package/dist/contracts/src/knowledge/spec.d.ts +8 -0
- package/dist/contracts/src/knowledge/spec.d.ts.map +1 -0
- package/dist/contracts/src/ownership.d.ts +61 -0
- package/dist/contracts/src/ownership.d.ts.map +1 -0
- package/dist/contracts/src/policy/spec.d.ts +11 -0
- package/dist/contracts/src/policy/spec.d.ts.map +1 -0
- package/dist/contracts/src/presentations/presentations.d.ts +2 -0
- package/dist/contracts/src/workflow/overview.docblock.d.ts +1 -0
- package/dist/contracts/src/workspace-config/workspace-config.docblock.d.ts +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +9 -0
- package/dist/rag/index.d.ts +2 -0
- package/dist/rag/index.js +3 -0
- package/dist/rag/ticket-resolver.d.ts +25 -0
- package/dist/rag/ticket-resolver.d.ts.map +1 -0
- package/dist/rag/ticket-resolver.js +64 -0
- package/dist/rag/ticket-resolver.js.map +1 -0
- package/dist/schema/src/EnumType.d.ts +2 -0
- package/dist/schema/src/FieldType.d.ts +2 -0
- package/dist/schema/src/GraphQLSchemaType.d.ts +2 -0
- package/dist/schema/src/JsonSchemaType.d.ts +2 -0
- package/dist/schema/src/ScalarTypeEnum.d.ts +1 -0
- package/dist/schema/src/SchemaModel.d.ts +4 -0
- package/dist/schema/src/SchemaModelType.d.ts +1 -0
- package/dist/schema/src/ZodSchemaType.d.ts +2 -0
- package/dist/schema/src/entity/defineEntity.d.ts +1 -0
- package/dist/schema/src/entity/generator.d.ts +1 -0
- package/dist/schema/src/entity/index.d.ts +3 -0
- package/dist/schema/src/entity/types.d.ts +1 -0
- package/dist/schema/src/index.d.ts +9 -0
- package/dist/spec.d.ts +14 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +35 -0
- package/dist/spec.js.map +1 -0
- package/dist/tickets/classifier.d.ts +25 -0
- package/dist/tickets/classifier.d.ts.map +1 -0
- package/dist/tickets/classifier.js +199 -0
- package/dist/tickets/classifier.js.map +1 -0
- package/dist/tickets/index.d.ts +2 -0
- package/dist/tickets/index.js +3 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/package.json +76 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/bot/tools.ts
|
|
4
|
+
const ticketSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
subject: z.string(),
|
|
7
|
+
body: z.string(),
|
|
8
|
+
channel: z.enum([
|
|
9
|
+
"email",
|
|
10
|
+
"chat",
|
|
11
|
+
"phone",
|
|
12
|
+
"portal"
|
|
13
|
+
]),
|
|
14
|
+
customerName: z.string().optional(),
|
|
15
|
+
customerEmail: z.string().optional(),
|
|
16
|
+
metadata: z.object().optional()
|
|
17
|
+
});
|
|
18
|
+
const supportCitationSchema = z.object({
|
|
19
|
+
label: z.string(),
|
|
20
|
+
url: z.string().optional(),
|
|
21
|
+
snippet: z.string().optional(),
|
|
22
|
+
score: z.number().optional()
|
|
23
|
+
});
|
|
24
|
+
const supportActionSchema = z.object({
|
|
25
|
+
type: z.enum([
|
|
26
|
+
"respond",
|
|
27
|
+
"escalate",
|
|
28
|
+
"refund",
|
|
29
|
+
"manual"
|
|
30
|
+
]),
|
|
31
|
+
label: z.string(),
|
|
32
|
+
payload: z.record(z.string(), z.string())
|
|
33
|
+
});
|
|
34
|
+
const supportResolutionSchema = z.object({
|
|
35
|
+
ticketId: z.string(),
|
|
36
|
+
answer: z.string(),
|
|
37
|
+
confidence: z.number(),
|
|
38
|
+
citations: supportCitationSchema.array(),
|
|
39
|
+
actions: supportActionSchema.array(),
|
|
40
|
+
escalationReason: z.string().optional(),
|
|
41
|
+
knowledgeUpdates: z.array(z.string()).optional()
|
|
42
|
+
});
|
|
43
|
+
const ticketClassificationSchema = z.object({
|
|
44
|
+
ticketId: z.string(),
|
|
45
|
+
category: z.enum([
|
|
46
|
+
"billing",
|
|
47
|
+
"technical",
|
|
48
|
+
"product",
|
|
49
|
+
"account",
|
|
50
|
+
"compliance",
|
|
51
|
+
"other"
|
|
52
|
+
]),
|
|
53
|
+
priority: z.enum([
|
|
54
|
+
"urgent",
|
|
55
|
+
"high",
|
|
56
|
+
"medium",
|
|
57
|
+
"low"
|
|
58
|
+
]),
|
|
59
|
+
sentiment: z.enum([
|
|
60
|
+
"positive",
|
|
61
|
+
"neutral",
|
|
62
|
+
"negative",
|
|
63
|
+
"frustrated"
|
|
64
|
+
]),
|
|
65
|
+
intents: z.array(z.string()),
|
|
66
|
+
tags: z.array(z.string()),
|
|
67
|
+
confidence: z.number(),
|
|
68
|
+
escalationRequired: z.boolean().optional()
|
|
69
|
+
});
|
|
70
|
+
function ensureTicket(input) {
|
|
71
|
+
if (!input || typeof input !== "object" || !("ticket" in input)) throw new Error("Input must include ticket");
|
|
72
|
+
const ticket = input.ticket;
|
|
73
|
+
if (!ticket?.id) throw new Error("Ticket is missing id");
|
|
74
|
+
return ticket;
|
|
75
|
+
}
|
|
76
|
+
function extractResolution(input) {
|
|
77
|
+
if (!input || typeof input !== "object" || !("resolution" in input)) return void 0;
|
|
78
|
+
return input.resolution;
|
|
79
|
+
}
|
|
80
|
+
function extractClassification(input) {
|
|
81
|
+
if (!input || typeof input !== "object" || !("classification" in input)) return void 0;
|
|
82
|
+
return input.classification;
|
|
83
|
+
}
|
|
84
|
+
function createSupportTools(options) {
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
title: "support_classify_ticket",
|
|
88
|
+
description: "Classify a ticket for priority, sentiment, and category",
|
|
89
|
+
inputSchema: z.object({ ticket: ticketSchema }),
|
|
90
|
+
execute: async (input) => {
|
|
91
|
+
const ticket = ensureTicket(input);
|
|
92
|
+
const classification = await options.classifier.classify(ticket);
|
|
93
|
+
return {
|
|
94
|
+
content: JSON.stringify(classification),
|
|
95
|
+
metadata: { ticketId: ticket.id }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
title: "support_resolve_ticket",
|
|
101
|
+
description: "Generate a knowledge-grounded resolution for a ticket",
|
|
102
|
+
inputSchema: z.object({ ticket: ticketSchema }),
|
|
103
|
+
execute: async (input) => {
|
|
104
|
+
const ticket = ensureTicket(input);
|
|
105
|
+
const resolution = await options.resolver.resolve(ticket);
|
|
106
|
+
return {
|
|
107
|
+
content: JSON.stringify(resolution),
|
|
108
|
+
metadata: { ticketId: ticket.id }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
title: "support_draft_response",
|
|
114
|
+
description: "Draft a user-facing reply based on resolution + classification",
|
|
115
|
+
inputSchema: z.object({
|
|
116
|
+
ticket: ticketSchema,
|
|
117
|
+
resolution: supportResolutionSchema,
|
|
118
|
+
classification: ticketClassificationSchema
|
|
119
|
+
}),
|
|
120
|
+
execute: async (input) => {
|
|
121
|
+
const ticket = ensureTicket(input);
|
|
122
|
+
const resolution = extractResolution(input);
|
|
123
|
+
const classification = extractClassification(input);
|
|
124
|
+
if (!resolution || !classification) throw new Error("resolution and classification are required");
|
|
125
|
+
const draft = await options.responder.draft(ticket, resolution, classification);
|
|
126
|
+
return {
|
|
127
|
+
content: JSON.stringify(draft),
|
|
128
|
+
metadata: { ticketId: ticket.id }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { createSupportTools };
|
|
137
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","names":[],"sources":["../../src/bot/tools.ts"],"sourcesContent":["import type { TicketResolver } from '../rag/ticket-resolver';\nimport type { TicketClassifier } from '../tickets/classifier';\nimport type { AutoResponder } from './auto-responder';\nimport type {\n SupportAction,\n SupportCitation,\n SupportResolution,\n SupportTicket,\n TicketCategory,\n TicketClassification,\n TicketPriority,\n TicketSentiment,\n} from '../types';\nimport type { Tool } from '@ai-sdk/provider-utils';\nimport * as z from 'zod';\n\nconst ticketSchema = z.object({\n id: z.string(),\n subject: z.string(),\n body: z.string(),\n channel: z.enum(['email', 'chat', 'phone', 'portal']),\n customerName: z.string().optional(),\n customerEmail: z.string().optional(),\n metadata: z.object().optional(),\n}) satisfies z.ZodType<SupportTicket>;\nconst supportCitationSchema = z.object({\n label: z.string(),\n url: z.string().optional(),\n snippet: z.string().optional(),\n score: z.number().optional(),\n}) satisfies z.ZodType<SupportCitation>;\nconst supportActionSchema = z.object({\n type: z.enum(['respond', 'escalate', 'refund', 'manual']),\n label: z.string(),\n payload: z.record(z.string(), z.string()),\n}) satisfies z.ZodType<SupportAction>;\nconst supportResolutionSchema = z.object({\n ticketId: z.string(),\n answer: z.string(),\n confidence: z.number(),\n citations: supportCitationSchema.array(),\n actions: supportActionSchema.array(),\n escalationReason: z.string().optional(),\n knowledgeUpdates: z.array(z.string()).optional(),\n}) satisfies z.ZodType<SupportResolution>;\nconst ticketClassificationSchema = z.object({\n ticketId: z.string(),\n category: z.enum([\n 'billing',\n 'technical',\n 'product',\n 'account',\n 'compliance',\n 'other',\n ]) satisfies z.ZodType<TicketCategory>,\n priority: z.enum([\n 'urgent',\n 'high',\n 'medium',\n 'low',\n ]) satisfies z.ZodType<TicketPriority>,\n sentiment: z.enum([\n 'positive',\n 'neutral',\n 'negative',\n 'frustrated',\n ]) satisfies z.ZodType<TicketSentiment>,\n intents: z.array(z.string()),\n tags: z.array(z.string()),\n confidence: z.number(),\n escalationRequired: z.boolean().optional(),\n}) satisfies z.ZodType<TicketClassification>;\n\nfunction ensureTicket(input: unknown): SupportTicket {\n if (!input || typeof input !== 'object' || !('ticket' in input)) {\n throw new Error('Input must include ticket');\n }\n const ticket = (input as { ticket: SupportTicket }).ticket;\n if (!ticket?.id) throw new Error('Ticket is missing id');\n return ticket;\n}\n\nfunction extractResolution(input: unknown): SupportResolution | undefined {\n if (!input || typeof input !== 'object' || !('resolution' in input))\n return undefined;\n return (input as { resolution?: SupportResolution }).resolution;\n}\n\nfunction extractClassification(\n input: unknown\n): TicketClassification | undefined {\n if (!input || typeof input !== 'object' || !('classification' in input))\n return undefined;\n return (input as { classification?: TicketClassification }).classification;\n}\n\nexport interface SupportToolsetOptions {\n resolver: TicketResolver;\n classifier: TicketClassifier;\n responder: AutoResponder;\n}\n\nexport function createSupportTools(options: SupportToolsetOptions): Tool[] {\n const classifyTool: Tool = {\n title: 'support_classify_ticket',\n description: 'Classify a ticket for priority, sentiment, and category',\n inputSchema: z.object({ ticket: ticketSchema }),\n execute: async (input: unknown) => {\n const ticket = ensureTicket(input);\n const classification = await options.classifier.classify(ticket);\n return {\n content: JSON.stringify(classification),\n metadata: { ticketId: ticket.id },\n };\n },\n };\n\n const resolveTool: Tool = {\n title: 'support_resolve_ticket',\n description: 'Generate a knowledge-grounded resolution for a ticket',\n inputSchema: z.object({ ticket: ticketSchema }),\n execute: async (input: unknown) => {\n const ticket = ensureTicket(input);\n const resolution = await options.resolver.resolve(ticket);\n return {\n content: JSON.stringify(resolution),\n metadata: { ticketId: ticket.id },\n };\n },\n };\n\n const responderTool: Tool = {\n title: 'support_draft_response',\n description:\n 'Draft a user-facing reply based on resolution + classification',\n inputSchema: z.object({\n ticket: ticketSchema,\n resolution: supportResolutionSchema,\n classification: ticketClassificationSchema,\n }),\n execute: async (input: unknown) => {\n const ticket = ensureTicket(input);\n const resolution = extractResolution(input);\n const classification = extractClassification(input);\n if (!resolution || !classification) {\n throw new Error('resolution and classification are required');\n }\n const draft = await options.responder.draft(\n ticket,\n resolution,\n classification\n );\n return {\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AEJ;EAE2B;GAC1B,OAAO;GACP,aACE;GACF,aAAa,EAAE,OAAO;IACpB,QAAQ;IACR,YAAY;IACZ,gBAAgB;IACjB,CAAC;GACF,SAAS,OAAO,UAAmB;IACjC,MAAM,SAAS,aAAa,MAAM;IAClC,MAAM,aAAa,kBAAkB,MAAM;IAC3C,MAAM,iBAAiB,sBAAsB,MAAM;AACnD,QAAI,CAAC,cAAc,CAAC,eAClB,OAAM,IAAI,MAAM,6CAA6C;IAE/D,MAAM,QAAQ,MAAM,QAAQ,UAAU,MACpC,QACA,YACA,eACD;AACD,WAAO;KACL,SAAS,KAAK,UAAU,MAAM;KAC9B,UAAU,EAAE,UAAU,OAAO,IAAI;KAClC;;GAEJ;EAEgD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./index.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "./presentations.js";
|
|
2
|
+
import { DocId } from "./registry.js";
|
|
3
|
+
import "./accessibility_wcag_compliance_specs.docblock.js";
|
|
4
|
+
import "./tech/lifecycle-stage-system.docblock.js";
|
|
5
|
+
import "./tech/presentation-runtime.docblock.js";
|
|
6
|
+
import "./tech/auth/better-auth-nextjs.docblock.js";
|
|
7
|
+
import "./tech/schema/README.docblock.js";
|
|
8
|
+
import "./tech/templates/runtime.docblock.js";
|
|
9
|
+
import "../workflow/overview.docblock.js";
|
|
10
|
+
import "./tech/mcp-endpoints.docblock.js";
|
|
11
|
+
import "./tech/vscode-extension.docblock.js";
|
|
12
|
+
import "./tech/telemetry-ingest.docblock.js";
|
|
13
|
+
import "./tech/contracts/openapi-export.docblock.js";
|
|
14
|
+
import "./tech/contracts/openapi-import.docblock.js";
|
|
15
|
+
import "../workspace-config/workspace-config.docblock.js";
|
|
16
|
+
import "./tech/studio/workspaces.docblock.js";
|
|
17
|
+
import "./tech/studio/sandbox-unlogged.docblock.js";
|
|
18
|
+
import "./tech/studio/workspace-ops.docblock.js";
|
|
19
|
+
import "./tech/studio/project-routing.docblock.js";
|
|
20
|
+
import "./tech/studio/platform-admin-panel.docblock.js";
|
|
21
|
+
import "./tech/studio/learning-events.docblock.js";
|
|
22
|
+
import "./tech/studio/learning-journeys.docblock.js";
|
|
23
|
+
import "./tech/studio/project-access-teams.docblock.js";
|
|
24
|
+
import "./tech/studio/team-invitations.docblock.js";
|
|
25
|
+
import "./tech/llm/llm-integration.docblock.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../../../../contracts/src/docs/registry.ts"],"sourcesContent":[],"mappings":";;;;KASY,KAAA;EAAA,OAAA,EAAK,IAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.js";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region ../contracts/src/integrations/providers/llm.d.ts
|
|
2
|
+
type LLMRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
3
|
+
interface LLMTextPart {
|
|
4
|
+
type: 'text';
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
interface LLMToolCallPart {
|
|
8
|
+
type: 'tool-call';
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
arguments: string;
|
|
12
|
+
}
|
|
13
|
+
interface LLMToolResultPart {
|
|
14
|
+
type: 'tool-result';
|
|
15
|
+
toolCallId: string;
|
|
16
|
+
output: string;
|
|
17
|
+
}
|
|
18
|
+
type LLMContentPart = LLMTextPart | LLMToolCallPart | LLMToolResultPart;
|
|
19
|
+
interface LLMMessage {
|
|
20
|
+
role: LLMRole;
|
|
21
|
+
content: LLMContentPart[];
|
|
22
|
+
name?: string;
|
|
23
|
+
toolCallId?: string;
|
|
24
|
+
metadata?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
interface LLMToolDefinition {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
inputSchema: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface LLMTokenUsage {
|
|
32
|
+
promptTokens: number;
|
|
33
|
+
completionTokens: number;
|
|
34
|
+
totalTokens: number;
|
|
35
|
+
}
|
|
36
|
+
interface LLMChatOptions {
|
|
37
|
+
model?: string;
|
|
38
|
+
temperature?: number;
|
|
39
|
+
topP?: number;
|
|
40
|
+
maxOutputTokens?: number;
|
|
41
|
+
stopSequences?: string[];
|
|
42
|
+
responseFormat?: 'text' | 'json';
|
|
43
|
+
tools?: LLMToolDefinition[];
|
|
44
|
+
userId?: string;
|
|
45
|
+
metadata?: Record<string, string>;
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}
|
|
49
|
+
interface LLMResponse {
|
|
50
|
+
message: LLMMessage;
|
|
51
|
+
usage?: LLMTokenUsage;
|
|
52
|
+
finishReason?: 'stop' | 'length' | 'tool_call' | 'content_filter';
|
|
53
|
+
raw?: unknown;
|
|
54
|
+
}
|
|
55
|
+
type LLMStreamChunk = {
|
|
56
|
+
type: 'message_delta';
|
|
57
|
+
delta: LLMContentPart;
|
|
58
|
+
index: number;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'tool_call';
|
|
61
|
+
call: LLMToolCallPart;
|
|
62
|
+
index: number;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'usage';
|
|
65
|
+
usage: LLMTokenUsage;
|
|
66
|
+
} | {
|
|
67
|
+
type: 'error';
|
|
68
|
+
error: Error;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'end';
|
|
71
|
+
response: LLMResponse;
|
|
72
|
+
};
|
|
73
|
+
interface TokenCountResult {
|
|
74
|
+
promptTokens: number;
|
|
75
|
+
}
|
|
76
|
+
interface LLMProvider {
|
|
77
|
+
chat(messages: LLMMessage[], options?: LLMChatOptions): Promise<LLMResponse>;
|
|
78
|
+
stream(messages: LLMMessage[], options?: LLMChatOptions): AsyncIterable<LLMStreamChunk>;
|
|
79
|
+
countTokens(messages: LLMMessage[]): Promise<TokenCountResult>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { LLMProvider };
|
|
83
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","names":[],"sources":["../../../../../../contracts/src/integrations/providers/llm.ts"],"sourcesContent":[],"mappings":";KAAY,OAAA;AAAA,UAEK,WAAA,CAFE;EAEF,IAAA,EAAA,MAAA;EAKA,IAAA,EAAA,MAAA;AAOjB;AAMY,UAbK,eAAA,CAaS;EAAG,IAAA,EAAA,WAAA;EAAc,EAAA,EAAA,MAAA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1,8 @@
|
|
|
1
|
+
import "../ownership.js";
|
|
2
|
+
import "../policy/spec.js";
|
|
3
|
+
|
|
4
|
+
//#region ../contracts/src/knowledge/spec.d.ts
|
|
5
|
+
type KnowledgeCategory = 'canonical' | 'operational' | 'external' | 'ephemeral';
|
|
6
|
+
//#endregion
|
|
7
|
+
export { KnowledgeCategory };
|
|
8
|
+
//# sourceMappingURL=spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../../../../contracts/src/knowledge/spec.ts"],"sourcesContent":[],"mappings":";;;;KAGY,iBAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DocId } from "./docs/registry.js";
|
|
2
|
+
import "./docs/index.js";
|
|
3
|
+
|
|
4
|
+
//#region ../contracts/src/ownership.d.ts
|
|
5
|
+
declare const StabilityEnum: {
|
|
6
|
+
readonly Idea: "idea";
|
|
7
|
+
readonly InCreation: "in_creation";
|
|
8
|
+
readonly Experimental: "experimental";
|
|
9
|
+
readonly Beta: "beta";
|
|
10
|
+
readonly Stable: "stable";
|
|
11
|
+
readonly Deprecated: "deprecated";
|
|
12
|
+
};
|
|
13
|
+
type Stability = (typeof StabilityEnum)[keyof typeof StabilityEnum];
|
|
14
|
+
declare const OwnersEnum: {
|
|
15
|
+
readonly PlatformCore: "platform.core";
|
|
16
|
+
readonly PlatformSigil: "platform.sigil";
|
|
17
|
+
readonly PlatformMarketplace: "platform.marketplace";
|
|
18
|
+
readonly PlatformMessaging: "platform.messaging";
|
|
19
|
+
readonly PlatformContent: "platform.content";
|
|
20
|
+
readonly PlatformFeatureFlags: "platform.featureflags";
|
|
21
|
+
readonly PlatformFinance: "platform.finance";
|
|
22
|
+
};
|
|
23
|
+
type Owner = (typeof OwnersEnum)[keyof typeof OwnersEnum] | (string & {});
|
|
24
|
+
declare const TagsEnum: {
|
|
25
|
+
readonly Spots: "spots";
|
|
26
|
+
readonly Collectivity: "collectivity";
|
|
27
|
+
readonly Marketplace: "marketplace";
|
|
28
|
+
readonly Sellers: "sellers";
|
|
29
|
+
readonly Auth: "auth";
|
|
30
|
+
readonly Login: "login";
|
|
31
|
+
readonly Signup: "signup";
|
|
32
|
+
readonly Guide: "guide";
|
|
33
|
+
readonly Docs: "docs";
|
|
34
|
+
readonly I18n: "i18n";
|
|
35
|
+
readonly Incident: "incident";
|
|
36
|
+
readonly Automation: "automation";
|
|
37
|
+
readonly Hygiene: "hygiene";
|
|
38
|
+
};
|
|
39
|
+
type Tag = (typeof TagsEnum)[keyof typeof TagsEnum] | (string & {});
|
|
40
|
+
interface OwnerShipMeta {
|
|
41
|
+
/** Breaking changes => bump version */
|
|
42
|
+
version: number;
|
|
43
|
+
/** Fully-qualified spec key (e.g., "sigil.beginSignup") */
|
|
44
|
+
key: string;
|
|
45
|
+
/** Human-friendly spec title (e.g., "Signup begin") */
|
|
46
|
+
title?: string;
|
|
47
|
+
/** Short human-friendly summary */
|
|
48
|
+
description: string;
|
|
49
|
+
domain?: string;
|
|
50
|
+
/** Lifecycle marker for comms & tooling */
|
|
51
|
+
stability: Stability;
|
|
52
|
+
/** Owners for CODEOWNERS / on-call / approvals */
|
|
53
|
+
owners: Owner[];
|
|
54
|
+
/** Search tags, grouping, docs navigation */
|
|
55
|
+
tags: Tag[];
|
|
56
|
+
/** Doc block(s) for this operation. */
|
|
57
|
+
docId?: DocId[];
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { OwnerShipMeta };
|
|
61
|
+
//# sourceMappingURL=ownership.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership.d.ts","names":[],"sources":["../../../../contracts/src/ownership.ts"],"sourcesContent":[],"mappings":";;;;cAIa;;;EAAA,SAAA,YAOH,EAAA,cAAA;EACE,SAAA,IAAS,EAAA,MAAA;EAGR,SAAA,MAQH,EAAA,QAAA;EACE,SAAK,UAAA,EACL,YAAyB;AAMrC,CAAA;AAeY,KAlCA,SAAA,GAkCc,CAAA,OAlCM,aAkCyB,CAAA,CAAA,MAAA,OAlCG,aAkCH,CAAA;AAIxC,cAnCJ,UAmCiB,EAAA;EAWjB,SAAA,YAAA,EAAA,eAAA;EAEH,SAAA,aAAA,EAAA,gBAAA;EAEF,SAAA,mBAAA,EAAA,sBAAA;EAGE,SAAA,iBAAA,EAAA,oBAAA;EAAK,SAAA,eAAA,EAAA,kBAAA;;;;KA5CH,KAAA,WACA,yBAAyB;cAMxB;;;;;;;;;;;;;;;KAeD,GAAA,WAAc,uBAAuB;UAIhC,aAAA;;;;;;;;;;;aAWJ;;UAEH;;QAEF;;UAGE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../../../../contracts/src/policy/spec.ts"],"sourcesContent":[],"mappings":";;;;UAmHiB,SAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../docs/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../docs/index.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClassificationResultPayload, ResolutionResultPayload, SupportAction, SupportBotSpec, SupportCitation, SupportResolution, SupportResponseDraft, SupportTicket, TicketCategory, TicketChannel, TicketClassification, TicketPriority, TicketSentiment } from "./types.js";
|
|
2
|
+
import { AutoResponder, AutoResponderOptions } from "./bot/auto-responder.js";
|
|
3
|
+
import { FeedbackMetrics, SupportFeedbackLoop } from "./bot/feedback-loop.js";
|
|
4
|
+
import { KnowledgeRetriever, TicketResolver, TicketResolverOptions } from "./rag/ticket-resolver.js";
|
|
5
|
+
import { TicketClassifier, TicketClassifierOptions } from "./tickets/classifier.js";
|
|
6
|
+
import { SupportToolsetOptions, createSupportTools } from "./bot/tools.js";
|
|
7
|
+
import "./bot/index.js";
|
|
8
|
+
import { SupportBotDefinition, defineSupportBot } from "./spec.js";
|
|
9
|
+
import "./rag/index.js";
|
|
10
|
+
import "./tickets/index.js";
|
|
11
|
+
export { AutoResponder, AutoResponderOptions, ClassificationResultPayload, FeedbackMetrics, KnowledgeRetriever, ResolutionResultPayload, SupportAction, SupportBotDefinition, SupportBotSpec, SupportCitation, SupportFeedbackLoop, SupportResolution, SupportResponseDraft, SupportTicket, SupportToolsetOptions, TicketCategory, TicketChannel, TicketClassification, TicketClassifier, TicketClassifierOptions, TicketPriority, TicketResolver, TicketResolverOptions, TicketSentiment, createSupportTools, defineSupportBot };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineSupportBot } from "./spec.js";
|
|
2
|
+
import { TicketResolver } from "./rag/ticket-resolver.js";
|
|
3
|
+
import { TicketClassifier } from "./tickets/classifier.js";
|
|
4
|
+
import { AutoResponder } from "./bot/auto-responder.js";
|
|
5
|
+
import { SupportFeedbackLoop } from "./bot/feedback-loop.js";
|
|
6
|
+
import { createSupportTools } from "./bot/tools.js";
|
|
7
|
+
import "./bot/index.js";
|
|
8
|
+
|
|
9
|
+
export { AutoResponder, SupportFeedbackLoop, TicketClassifier, TicketResolver, createSupportTools, defineSupportBot };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SupportResolution, SupportTicket } from "../types.js";
|
|
2
|
+
import { KnowledgeAnswer } from "@contractspec/lib.knowledge/query/service";
|
|
3
|
+
|
|
4
|
+
//#region src/rag/ticket-resolver.d.ts
|
|
5
|
+
interface KnowledgeRetriever {
|
|
6
|
+
query(question: string): Promise<KnowledgeAnswer>;
|
|
7
|
+
}
|
|
8
|
+
interface TicketResolverOptions {
|
|
9
|
+
knowledge: KnowledgeRetriever;
|
|
10
|
+
minConfidence?: number;
|
|
11
|
+
prependPrompt?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class TicketResolver {
|
|
14
|
+
private readonly knowledge;
|
|
15
|
+
private readonly minConfidence;
|
|
16
|
+
private readonly prependPrompt?;
|
|
17
|
+
constructor(options: TicketResolverOptions);
|
|
18
|
+
resolve(ticket: SupportTicket): Promise<SupportResolution>;
|
|
19
|
+
private buildQuestion;
|
|
20
|
+
private toResolution;
|
|
21
|
+
private deriveConfidence;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { KnowledgeRetriever, TicketResolver, TicketResolverOptions };
|
|
25
|
+
//# sourceMappingURL=ticket-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket-resolver.d.ts","names":[],"sources":["../../src/rag/ticket-resolver.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,kBAAA;2BACU,QAAQ;AADnC;AAIiB,UAAA,qBAAA,CAAqB;EAMzB,SAAA,EALA,kBAKc;EAKJ,aAAA,CAAA,EAAA,MAAA;EAMC,aAAA,CAAA,EAAA,MAAA;;AAAgB,cAX3B,cAAA,CAW2B;EAAO,iBAAA,SAAA;;;uBANxB;kBAMC,gBAAgB,QAAQ"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/rag/ticket-resolver.ts
|
|
2
|
+
var TicketResolver = class {
|
|
3
|
+
knowledge;
|
|
4
|
+
minConfidence;
|
|
5
|
+
prependPrompt;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.knowledge = options.knowledge;
|
|
8
|
+
this.minConfidence = options.minConfidence ?? .65;
|
|
9
|
+
this.prependPrompt = options.prependPrompt;
|
|
10
|
+
}
|
|
11
|
+
async resolve(ticket) {
|
|
12
|
+
const question = this.buildQuestion(ticket);
|
|
13
|
+
const answer = await this.knowledge.query(question);
|
|
14
|
+
return this.toResolution(ticket, answer);
|
|
15
|
+
}
|
|
16
|
+
buildQuestion(ticket) {
|
|
17
|
+
const header = [`Subject: ${ticket.subject}`, `Channel: ${ticket.channel}`];
|
|
18
|
+
if (ticket.customerName) header.push(`Customer: ${ticket.customerName}`);
|
|
19
|
+
return [
|
|
20
|
+
this.prependPrompt,
|
|
21
|
+
header.join("\n"),
|
|
22
|
+
"---",
|
|
23
|
+
ticket.body
|
|
24
|
+
].filter(Boolean).join("\n");
|
|
25
|
+
}
|
|
26
|
+
toResolution(ticket, answer) {
|
|
27
|
+
const citations = answer.references.map((ref) => {
|
|
28
|
+
return {
|
|
29
|
+
label: typeof ref.payload?.title === "string" ? ref.payload.title : typeof ref.payload?.documentId === "string" ? ref.payload.documentId : ref.id,
|
|
30
|
+
url: typeof ref.payload?.url === "string" ? ref.payload.url : void 0,
|
|
31
|
+
snippet: typeof ref.payload?.text === "string" ? ref.payload.text.slice(0, 280) : void 0,
|
|
32
|
+
score: ref.score
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const confidence = this.deriveConfidence(answer);
|
|
36
|
+
const escalate = confidence < this.minConfidence || citations.length === 0;
|
|
37
|
+
return {
|
|
38
|
+
ticketId: ticket.id,
|
|
39
|
+
answer: answer.answer,
|
|
40
|
+
confidence,
|
|
41
|
+
citations,
|
|
42
|
+
actions: [escalate ? {
|
|
43
|
+
type: "escalate",
|
|
44
|
+
label: "Escalate for human review"
|
|
45
|
+
} : {
|
|
46
|
+
type: "respond",
|
|
47
|
+
label: "Send automated response"
|
|
48
|
+
}],
|
|
49
|
+
escalationReason: escalate ? "Insufficient confidence or missing knowledge references" : void 0,
|
|
50
|
+
knowledgeUpdates: escalate ? [ticket.body.slice(0, 200)] : void 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
deriveConfidence(answer) {
|
|
54
|
+
if (!answer.references.length) return .3;
|
|
55
|
+
const topScore = answer.references[0]?.score ?? .4;
|
|
56
|
+
const normalized = Math.min(1, Math.max(0, topScore));
|
|
57
|
+
const tokenPenalty = answer.usage?.completionTokens ? Math.min(answer.usage.completionTokens / 1e3, .2) : 0;
|
|
58
|
+
return Number((normalized - tokenPenalty).toFixed(2));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { TicketResolver };
|
|
64
|
+
//# sourceMappingURL=ticket-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket-resolver.js","names":[],"sources":["../../src/rag/ticket-resolver.ts"],"sourcesContent":["import type { KnowledgeAnswer } from '@contractspec/lib.knowledge/query/service';\nimport type { SupportResolution, SupportTicket } from '../types';\n\nexport interface KnowledgeRetriever {\n query(question: string): Promise<KnowledgeAnswer>;\n}\n\nexport interface TicketResolverOptions {\n knowledge: KnowledgeRetriever;\n minConfidence?: number;\n prependPrompt?: string;\n}\n\nexport class TicketResolver {\n private readonly knowledge: KnowledgeRetriever;\n private readonly minConfidence: number;\n private readonly prependPrompt?: string;\n\n constructor(options: TicketResolverOptions) {\n this.knowledge = options.knowledge;\n this.minConfidence = options.minConfidence ?? 0.65;\n this.prependPrompt = options.prependPrompt;\n }\n\n async resolve(ticket: SupportTicket): Promise<SupportResolution> {\n const question = this.buildQuestion(ticket);\n const answer = await this.knowledge.query(question);\n return this.toResolution(ticket, answer);\n }\n\n private buildQuestion(ticket: SupportTicket): string {\n const header = [`Subject: ${ticket.subject}`, `Channel: ${ticket.channel}`];\n if (ticket.customerName) header.push(`Customer: ${ticket.customerName}`);\n const sections = [\n this.prependPrompt,\n header.join('\\n'),\n '---',\n ticket.body,\n ].filter(Boolean);\n return sections.join('\\n');\n }\n\n private toResolution(\n ticket: SupportTicket,\n answer: KnowledgeAnswer\n ): SupportResolution {\n const citations = answer.references.map((ref) => {\n const label =\n typeof ref.payload?.title === 'string'\n ? ref.payload.title\n : typeof ref.payload?.documentId === 'string'\n ? ref.payload.documentId\n : ref.id;\n return {\n label,\n url: typeof ref.payload?.url === 'string' ? ref.payload.url : undefined,\n snippet:\n typeof ref.payload?.text === 'string'\n ? ref.payload.text.slice(0, 280)\n : undefined,\n score: ref.score,\n };\n });\n\n const confidence = this.deriveConfidence(answer);\n const escalate = confidence < this.minConfidence || citations.length === 0;\n\n return {\n ticketId: ticket.id,\n answer: answer.answer,\n confidence,\n citations,\n actions: [\n escalate\n ? { type: 'escalate', label: 'Escalate for human review' }\n : { type: 'respond', label: 'Send automated response' },\n ],\n escalationReason: escalate\n ? 'Insufficient confidence or missing knowledge references'\n : undefined,\n knowledgeUpdates: escalate ? [ticket.body.slice(0, 200)] : undefined,\n };\n }\n\n private deriveConfidence(answer: KnowledgeAnswer): number {\n if (!answer.references.length) return 0.3;\n const topScore = answer.references[0]?.score ?? 0.4;\n const normalized = Math.min(1, Math.max(0, topScore));\n const tokenPenalty = answer.usage?.completionTokens\n ? Math.min(answer.usage.completionTokens / 1000, 0.2)\n : 0;\n return Number((normalized - tokenPenalty).toFixed(2));\n }\n}\n"],"mappings":";AAaA,IAAa,iBAAb,MAA4B;CAC1B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YAAY,SAAgC;AAC1C,OAAK,YAAY,QAAQ;AACzB,OAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,OAAK,gBAAgB,QAAQ;;CAG/B,MAAM,QAAQ,QAAmD;EAC/D,MAAM,WAAW,KAAK,cAAc,OAAO;EAC3C,MAAM,SAAS,MAAM,KAAK,UAAU,MAAM,SAAS;AACnD,SAAO,KAAK,aAAa,QAAQ,OAAO;;CAG1C,AAAQ,cAAc,QAA+B;EACnD,MAAM,SAAS,CAAC,YAAY,OAAO,WAAW,YAAY,OAAO,UAAU;AAC3E,MAAI,OAAO,aAAc,QAAO,KAAK,aAAa,OAAO,eAAe;AAOxE,SANiB;GACf,KAAK;GACL,OAAO,KAAK,KAAK;GACjB;GACA,OAAO;GACR,CAAC,OAAO,QAAQ,CACD,KAAK,KAAK;;CAG5B,AAAQ,aACN,QACA,QACmB;EACnB,MAAM,YAAY,OAAO,WAAW,KAAK,QAAQ;AAO/C,UAAO;IACL,OANA,OAAO,IAAI,SAAS,UAAU,WAC1B,IAAI,QAAQ,QACZ,OAAO,IAAI,SAAS,eAAe,WACjC,IAAI,QAAQ,aACZ,IAAI;IAGV,KAAK,OAAO,IAAI,SAAS,QAAQ,WAAW,IAAI,QAAQ,MAAM;IAC9D,SACE,OAAO,IA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