opc-agent 2.0.2 → 3.0.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 +603 -545
- package/dist/channels/voice.d.ts +59 -0
- package/dist/channels/voice.js +351 -1
- package/dist/cli.js +284 -5
- package/dist/core/agent.d.ts +9 -0
- package/dist/core/agent.js +49 -0
- package/dist/core/collaboration.d.ts +89 -0
- package/dist/core/collaboration.js +201 -0
- package/dist/deploy/index.d.ts +40 -0
- package/dist/deploy/index.js +261 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +47 -3
- package/dist/mcp/servers/calculator-mcp.d.ts +3 -0
- package/dist/mcp/servers/calculator-mcp.js +65 -0
- package/dist/mcp/servers/crypto-mcp.d.ts +3 -0
- package/dist/mcp/servers/crypto-mcp.js +108 -0
- package/dist/mcp/servers/database-mcp.d.ts +3 -0
- package/dist/mcp/servers/database-mcp.js +73 -0
- package/dist/mcp/servers/datetime-mcp.d.ts +3 -0
- package/dist/mcp/servers/datetime-mcp.js +71 -0
- package/dist/mcp/servers/filesystem.d.ts +3 -0
- package/dist/mcp/servers/filesystem.js +101 -0
- package/dist/mcp/servers/github-mcp.d.ts +3 -0
- package/dist/mcp/servers/github-mcp.js +60 -0
- package/dist/mcp/servers/index.d.ts +21 -0
- package/dist/mcp/servers/index.js +50 -0
- package/dist/mcp/servers/json-mcp.d.ts +3 -0
- package/dist/mcp/servers/json-mcp.js +126 -0
- package/dist/mcp/servers/memory-mcp.d.ts +3 -0
- package/dist/mcp/servers/memory-mcp.js +60 -0
- package/dist/mcp/servers/regex-mcp.d.ts +3 -0
- package/dist/mcp/servers/regex-mcp.js +56 -0
- package/dist/mcp/servers/web-mcp.d.ts +3 -0
- package/dist/mcp/servers/web-mcp.js +51 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +4 -1
- package/dist/memory/seed-loader.d.ts +51 -0
- package/dist/memory/seed-loader.js +200 -0
- package/dist/schema/oad.d.ts +292 -12
- package/dist/schema/oad.js +12 -1
- package/dist/security/guardrails.d.ts +50 -0
- package/dist/security/guardrails.js +197 -0
- package/dist/studio/server.d.ts +31 -1
- package/dist/studio/server.js +154 -3
- package/dist/studio-ui/index.html +1278 -662
- package/dist/tools/integrations/calendar.d.ts +3 -0
- package/dist/tools/integrations/calendar.js +73 -0
- package/dist/tools/integrations/code-exec.d.ts +3 -0
- package/dist/tools/integrations/code-exec.js +42 -0
- package/dist/tools/integrations/csv-analyzer.d.ts +3 -0
- package/dist/tools/integrations/csv-analyzer.js +142 -0
- package/dist/tools/integrations/database.d.ts +3 -0
- package/dist/tools/integrations/database.js +44 -0
- package/dist/tools/integrations/email-send.d.ts +3 -0
- package/dist/tools/integrations/email-send.js +104 -0
- package/dist/tools/integrations/git-tool.d.ts +3 -0
- package/dist/tools/integrations/git-tool.js +49 -0
- package/dist/tools/integrations/github-tool.d.ts +3 -0
- package/dist/tools/integrations/github-tool.js +77 -0
- package/dist/tools/integrations/image-gen.d.ts +3 -0
- package/dist/tools/integrations/image-gen.js +58 -0
- package/dist/tools/integrations/index.d.ts +30 -0
- package/dist/tools/integrations/index.js +107 -0
- package/dist/tools/integrations/jira.d.ts +3 -0
- package/dist/tools/integrations/jira.js +85 -0
- package/dist/tools/integrations/notion.d.ts +3 -0
- package/dist/tools/integrations/notion.js +71 -0
- package/dist/tools/integrations/npm-tool.d.ts +3 -0
- package/dist/tools/integrations/npm-tool.js +49 -0
- package/dist/tools/integrations/pdf-reader.d.ts +3 -0
- package/dist/tools/integrations/pdf-reader.js +91 -0
- package/dist/tools/integrations/slack.d.ts +3 -0
- package/dist/tools/integrations/slack.js +67 -0
- package/dist/tools/integrations/summarizer.d.ts +3 -0
- package/dist/tools/integrations/summarizer.js +49 -0
- package/dist/tools/integrations/translator.d.ts +3 -0
- package/dist/tools/integrations/translator.js +48 -0
- package/dist/tools/integrations/trello.d.ts +3 -0
- package/dist/tools/integrations/trello.js +60 -0
- package/dist/tools/integrations/vector-search.d.ts +3 -0
- package/dist/tools/integrations/vector-search.js +44 -0
- package/dist/tools/integrations/web-scraper.d.ts +3 -0
- package/dist/tools/integrations/web-scraper.js +48 -0
- package/dist/tools/integrations/web-search.d.ts +3 -0
- package/dist/tools/integrations/web-search.js +60 -0
- package/dist/tools/integrations/webhook.d.ts +3 -0
- package/dist/tools/integrations/webhook.js +39 -0
- package/dist/ui/components.d.ts +10 -0
- package/dist/ui/components.js +123 -0
- package/package.json +1 -1
- package/src/channels/voice.ts +365 -0
- package/src/cli.ts +294 -6
- package/src/core/agent.ts +56 -0
- package/src/core/collaboration.ts +275 -0
- package/src/deploy/index.ts +255 -0
- package/src/index.ts +21 -1
- package/src/mcp/servers/calculator-mcp.ts +65 -0
- package/src/mcp/servers/crypto-mcp.ts +73 -0
- package/src/mcp/servers/database-mcp.ts +72 -0
- package/src/mcp/servers/datetime-mcp.ts +69 -0
- package/src/mcp/servers/filesystem.ts +66 -0
- package/src/mcp/servers/github-mcp.ts +58 -0
- package/src/mcp/servers/index.ts +63 -0
- package/src/mcp/servers/json-mcp.ts +102 -0
- package/src/mcp/servers/memory-mcp.ts +56 -0
- package/src/mcp/servers/regex-mcp.ts +53 -0
- package/src/mcp/servers/web-mcp.ts +49 -0
- package/src/memory/index.ts +3 -0
- package/src/memory/seed-loader.ts +212 -0
- package/src/schema/oad.ts +13 -0
- package/src/security/guardrails.ts +248 -0
- package/src/studio/server.ts +166 -4
- package/src/studio-ui/index.html +1278 -662
- package/src/tools/integrations/calendar.ts +73 -0
- package/src/tools/integrations/code-exec.ts +39 -0
- package/src/tools/integrations/csv-analyzer.ts +92 -0
- package/src/tools/integrations/database.ts +44 -0
- package/src/tools/integrations/email-send.ts +76 -0
- package/src/tools/integrations/git-tool.ts +42 -0
- package/src/tools/integrations/github-tool.ts +76 -0
- package/src/tools/integrations/image-gen.ts +56 -0
- package/src/tools/integrations/index.ts +92 -0
- package/src/tools/integrations/jira.ts +83 -0
- package/src/tools/integrations/notion.ts +71 -0
- package/src/tools/integrations/npm-tool.ts +48 -0
- package/src/tools/integrations/pdf-reader.ts +58 -0
- package/src/tools/integrations/slack.ts +65 -0
- package/src/tools/integrations/summarizer.ts +49 -0
- package/src/tools/integrations/translator.ts +48 -0
- package/src/tools/integrations/trello.ts +60 -0
- package/src/tools/integrations/vector-search.ts +42 -0
- package/src/tools/integrations/web-scraper.ts +47 -0
- package/src/tools/integrations/web-search.ts +58 -0
- package/src/tools/integrations/webhook.ts +38 -0
- package/src/ui/components.ts +127 -0
- package/tests/brain-seed-extended.test.ts +490 -0
- package/tests/brain-seed.test.ts +239 -0
- package/tests/collaboration.test.ts +319 -0
- package/tests/deploy-and-dag.test.ts +196 -0
- package/tests/guardrails.test.ts +177 -0
- package/tests/integrations.test.ts +249 -0
- package/tests/mcp-servers.test.ts +260 -0
- package/tests/voice-enhanced.test.ts +169 -0
- package/dist/dtv/data.d.ts +0 -18
- package/dist/dtv/data.js +0 -25
- package/dist/dtv/trust.d.ts +0 -19
- package/dist/dtv/trust.js +0 -40
- package/dist/dtv/value.d.ts +0 -23
- package/dist/dtv/value.js +0 -38
- package/dist/marketplace/index.d.ts +0 -34
- package/dist/marketplace/index.js +0 -202
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrelloTool = void 0;
|
|
4
|
+
exports.TrelloTool = {
|
|
5
|
+
name: 'trello',
|
|
6
|
+
description: 'Interact with Trello: create cards, move cards, list boards. Requires TRELLO_API_KEY, TRELLO_TOKEN env vars.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
action: { type: 'string', enum: ['create_card', 'move_card', 'list_boards'], description: 'Action' },
|
|
11
|
+
list_id: { type: 'string', description: 'List ID (for create_card/move_card)' },
|
|
12
|
+
card_id: { type: 'string', description: 'Card ID (for move_card)' },
|
|
13
|
+
name: { type: 'string', description: 'Card name' },
|
|
14
|
+
description: { type: 'string', description: 'Card description' },
|
|
15
|
+
},
|
|
16
|
+
required: ['action'],
|
|
17
|
+
},
|
|
18
|
+
async execute(input) {
|
|
19
|
+
const key = process.env.TRELLO_API_KEY;
|
|
20
|
+
const token = process.env.TRELLO_TOKEN;
|
|
21
|
+
if (!key || !token)
|
|
22
|
+
return { content: 'Error: TRELLO_API_KEY, TRELLO_TOKEN required', isError: true };
|
|
23
|
+
const auth = `key=${key}&token=${token}`;
|
|
24
|
+
const action = String(input.action ?? '');
|
|
25
|
+
try {
|
|
26
|
+
if (action === 'create_card') {
|
|
27
|
+
if (!input.list_id || !input.name)
|
|
28
|
+
return { content: 'Error: list_id, name required', isError: true };
|
|
29
|
+
const res = await fetch(`https://api.trello.com/1/cards?${auth}`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify({ idList: input.list_id, name: input.name, desc: input.description ?? '' }),
|
|
33
|
+
});
|
|
34
|
+
const data = await res.json();
|
|
35
|
+
return { content: `Card created: ${data.shortUrl ?? data.id}` };
|
|
36
|
+
}
|
|
37
|
+
if (action === 'move_card') {
|
|
38
|
+
if (!input.card_id || !input.list_id)
|
|
39
|
+
return { content: 'Error: card_id, list_id required', isError: true };
|
|
40
|
+
await fetch(`https://api.trello.com/1/cards/${input.card_id}?${auth}`, {
|
|
41
|
+
method: 'PUT',
|
|
42
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
|
+
body: JSON.stringify({ idList: input.list_id }),
|
|
44
|
+
});
|
|
45
|
+
return { content: `Card ${input.card_id} moved to list ${input.list_id}` };
|
|
46
|
+
}
|
|
47
|
+
if (action === 'list_boards') {
|
|
48
|
+
const res = await fetch(`https://api.trello.com/1/members/me/boards?${auth}`);
|
|
49
|
+
const data = await res.json();
|
|
50
|
+
const summary = Array.isArray(data) ? data.map((b) => `${b.name} (${b.id})`).join('\n') : JSON.stringify(data);
|
|
51
|
+
return { content: summary };
|
|
52
|
+
}
|
|
53
|
+
return { content: `Unknown action: ${action}`, isError: true };
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return { content: `Trello error: ${err.message}`, isError: true };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=trello.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VectorSearchTool = void 0;
|
|
4
|
+
exports.VectorSearchTool = {
|
|
5
|
+
name: 'vector-search',
|
|
6
|
+
description: 'Search vector embeddings via DeepBrain or compatible API. Requires DEEPBRAIN_URL and DEEPBRAIN_API_KEY env vars.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
query: { type: 'string', description: 'Search query text' },
|
|
11
|
+
collection: { type: 'string', description: 'Collection/namespace to search' },
|
|
12
|
+
top_k: { type: 'number', description: 'Number of results (default: 5)' },
|
|
13
|
+
},
|
|
14
|
+
required: ['query'],
|
|
15
|
+
},
|
|
16
|
+
async execute(input) {
|
|
17
|
+
const baseUrl = process.env.DEEPBRAIN_URL;
|
|
18
|
+
const apiKey = process.env.DEEPBRAIN_API_KEY;
|
|
19
|
+
if (!baseUrl)
|
|
20
|
+
return { content: 'Error: DEEPBRAIN_URL required', isError: true };
|
|
21
|
+
const query = String(input.query ?? '');
|
|
22
|
+
if (!query)
|
|
23
|
+
return { content: 'Error: query required', isError: true };
|
|
24
|
+
try {
|
|
25
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
26
|
+
if (apiKey)
|
|
27
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
28
|
+
const res = await fetch(`${baseUrl}/api/search`, {
|
|
29
|
+
method: 'POST', headers,
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
query,
|
|
32
|
+
collection: input.collection ?? 'default',
|
|
33
|
+
top_k: Number(input.top_k ?? 5),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
const data = await res.json();
|
|
37
|
+
return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return { content: `Vector search error: ${err.message}`, isError: true };
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=vector-search.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebScraperTool = void 0;
|
|
4
|
+
exports.WebScraperTool = {
|
|
5
|
+
name: 'web-scraper',
|
|
6
|
+
description: 'Fetch and extract readable content from a URL.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
url: { type: 'string', description: 'URL to scrape' },
|
|
11
|
+
max_length: { type: 'number', description: 'Max characters to return (default: 5000)' },
|
|
12
|
+
},
|
|
13
|
+
required: ['url'],
|
|
14
|
+
},
|
|
15
|
+
async execute(input) {
|
|
16
|
+
const url = String(input.url ?? '');
|
|
17
|
+
if (!url)
|
|
18
|
+
return { content: 'Error: url required', isError: true };
|
|
19
|
+
const maxLen = Number(input.max_length ?? 5000);
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(url, {
|
|
22
|
+
headers: { 'User-Agent': 'Mozilla/5.0 (compatible; OPCAgent/1.0)' },
|
|
23
|
+
});
|
|
24
|
+
if (!res.ok)
|
|
25
|
+
return { content: `HTTP ${res.status}: ${res.statusText}`, isError: true };
|
|
26
|
+
const html = await res.text();
|
|
27
|
+
// Simple HTML to text extraction
|
|
28
|
+
const text = html
|
|
29
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
30
|
+
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
|
31
|
+
.replace(/<[^>]+>/g, ' ')
|
|
32
|
+
.replace(/ /g, ' ')
|
|
33
|
+
.replace(/&/g, '&')
|
|
34
|
+
.replace(/</g, '<')
|
|
35
|
+
.replace(/>/g, '>')
|
|
36
|
+
.replace(/"/g, '"')
|
|
37
|
+
.replace(/'/g, "'")
|
|
38
|
+
.replace(/\s+/g, ' ')
|
|
39
|
+
.trim();
|
|
40
|
+
const truncated = text.length > maxLen ? text.slice(0, maxLen) + '...(truncated)' : text;
|
|
41
|
+
return { content: truncated, metadata: { url, length: text.length } };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
return { content: `Scraper error: ${err.message}`, isError: true };
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=web-scraper.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSearchTool = void 0;
|
|
4
|
+
exports.WebSearchTool = {
|
|
5
|
+
name: 'web-search',
|
|
6
|
+
description: 'Search the web using SerpAPI, Tavily, or Brave Search. Requires SERPAPI_KEY, TAVILY_API_KEY, or BRAVE_SEARCH_KEY env var.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
query: { type: 'string', description: 'Search query' },
|
|
11
|
+
provider: { type: 'string', enum: ['serpapi', 'tavily', 'brave'], description: 'Search provider (auto-detects from env)' },
|
|
12
|
+
count: { type: 'number', description: 'Number of results (default: 5)' },
|
|
13
|
+
},
|
|
14
|
+
required: ['query'],
|
|
15
|
+
},
|
|
16
|
+
async execute(input) {
|
|
17
|
+
const query = String(input.query ?? '');
|
|
18
|
+
if (!query)
|
|
19
|
+
return { content: 'Error: query required', isError: true };
|
|
20
|
+
const count = Number(input.count ?? 5);
|
|
21
|
+
try {
|
|
22
|
+
const provider = String(input.provider ?? '');
|
|
23
|
+
if (provider === 'tavily' || process.env.TAVILY_API_KEY) {
|
|
24
|
+
const key = process.env.TAVILY_API_KEY;
|
|
25
|
+
if (!key)
|
|
26
|
+
return { content: 'Error: TAVILY_API_KEY required', isError: true };
|
|
27
|
+
const res = await fetch('https://api.tavily.com/search', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
body: JSON.stringify({ api_key: key, query, max_results: count }),
|
|
31
|
+
});
|
|
32
|
+
const data = await res.json();
|
|
33
|
+
return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
|
|
34
|
+
}
|
|
35
|
+
if (provider === 'brave' || process.env.BRAVE_SEARCH_KEY) {
|
|
36
|
+
const key = process.env.BRAVE_SEARCH_KEY;
|
|
37
|
+
if (!key)
|
|
38
|
+
return { content: 'Error: BRAVE_SEARCH_KEY required', isError: true };
|
|
39
|
+
const res = await fetch(`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}&count=${count}`, {
|
|
40
|
+
headers: { 'X-Subscription-Token': key, 'Accept': 'application/json' },
|
|
41
|
+
});
|
|
42
|
+
const data = await res.json();
|
|
43
|
+
return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
|
|
44
|
+
}
|
|
45
|
+
if (provider === 'serpapi' || process.env.SERPAPI_KEY) {
|
|
46
|
+
const key = process.env.SERPAPI_KEY;
|
|
47
|
+
if (!key)
|
|
48
|
+
return { content: 'Error: SERPAPI_KEY required', isError: true };
|
|
49
|
+
const res = await fetch(`https://serpapi.com/search.json?q=${encodeURIComponent(query)}&num=${count}&api_key=${key}`);
|
|
50
|
+
const data = await res.json();
|
|
51
|
+
return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
|
|
52
|
+
}
|
|
53
|
+
return { content: 'Error: No search API key configured (TAVILY_API_KEY, BRAVE_SEARCH_KEY, or SERPAPI_KEY)', isError: true };
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return { content: `Search error: ${err.message}`, isError: true };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebhookTool = void 0;
|
|
4
|
+
exports.WebhookTool = {
|
|
5
|
+
name: 'webhook',
|
|
6
|
+
description: 'Send HTTP requests to arbitrary webhook URLs. Supports POST and GET.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
url: { type: 'string', description: 'Webhook URL' },
|
|
11
|
+
method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], description: 'HTTP method (default: POST)' },
|
|
12
|
+
headers: { type: 'object', description: 'Custom headers as key-value pairs' },
|
|
13
|
+
body: { type: 'string', description: 'Request body (JSON string)' },
|
|
14
|
+
},
|
|
15
|
+
required: ['url'],
|
|
16
|
+
},
|
|
17
|
+
async execute(input) {
|
|
18
|
+
const url = String(input.url ?? '');
|
|
19
|
+
if (!url)
|
|
20
|
+
return { content: 'Error: url is required', isError: true };
|
|
21
|
+
const method = String(input.method ?? 'POST').toUpperCase();
|
|
22
|
+
const customHeaders = (input.headers ?? {});
|
|
23
|
+
const headers = { 'Content-Type': 'application/json', ...customHeaders };
|
|
24
|
+
try {
|
|
25
|
+
const opts = { method, headers };
|
|
26
|
+
if (method !== 'GET' && method !== 'HEAD' && input.body) {
|
|
27
|
+
opts.body = String(input.body);
|
|
28
|
+
}
|
|
29
|
+
const res = await fetch(url, opts);
|
|
30
|
+
const text = await res.text();
|
|
31
|
+
const truncated = text.length > 4000 ? text.slice(0, 4000) + '...(truncated)' : text;
|
|
32
|
+
return { content: `Status: ${res.status}\n${truncated}`, metadata: { status: res.status } };
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return { content: `Webhook error: ${err.message}`, isError: true };
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Widget — self-contained HTML+CSS+JS for embedding
|
|
3
|
+
*/
|
|
4
|
+
export interface ChatWidgetConfig {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
theme?: 'dark' | 'light';
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function generateChatWidget(config: ChatWidgetConfig): string;
|
|
10
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chat Widget — self-contained HTML+CSS+JS for embedding
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateChatWidget = generateChatWidget;
|
|
7
|
+
function generateChatWidget(config) {
|
|
8
|
+
const { endpoint, theme = 'dark', title = 'OPC Chat' } = config;
|
|
9
|
+
const isDark = theme === 'dark';
|
|
10
|
+
const bg = isDark ? '#1a1a2e' : '#ffffff';
|
|
11
|
+
const fg = isDark ? '#e0e0e0' : '#1a1a2e';
|
|
12
|
+
const inputBg = isDark ? '#16213e' : '#f0f0f0';
|
|
13
|
+
const msgUser = isDark ? '#0f3460' : '#e3f2fd';
|
|
14
|
+
const msgBot = isDark ? '#1a1a2e' : '#f5f5f5';
|
|
15
|
+
const accent = '#00d2ff';
|
|
16
|
+
return `<!DOCTYPE html>
|
|
17
|
+
<html lang="en">
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="UTF-8">
|
|
20
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
21
|
+
<title>${title}</title>
|
|
22
|
+
<style>
|
|
23
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
24
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: ${bg}; color: ${fg}; height: 100vh; display: flex; flex-direction: column; }
|
|
25
|
+
.chat-header { padding: 16px 20px; background: ${isDark ? '#16213e' : '#fafafa'}; border-bottom: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
|
|
26
|
+
.chat-header::before { content: '💬'; }
|
|
27
|
+
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
|
|
28
|
+
.msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
|
|
29
|
+
.msg.user { align-self: flex-end; background: ${msgUser}; border-bottom-right-radius: 4px; }
|
|
30
|
+
.msg.assistant { align-self: flex-start; background: ${msgBot}; border: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; border-bottom-left-radius: 4px; }
|
|
31
|
+
.msg.streaming::after { content: '▊'; animation: blink 0.7s infinite; }
|
|
32
|
+
@keyframes blink { 50% { opacity: 0; } }
|
|
33
|
+
.chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; background: ${isDark ? '#16213e' : '#fafafa'}; }
|
|
34
|
+
.chat-input textarea { flex: 1; resize: none; border: 1px solid ${isDark ? '#2a2a4a' : '#ccc'}; border-radius: 8px; padding: 10px; font-size: 14px; background: ${inputBg}; color: ${fg}; outline: none; font-family: inherit; min-height: 42px; max-height: 120px; }
|
|
35
|
+
.chat-input textarea:focus { border-color: ${accent}; }
|
|
36
|
+
.chat-input button { background: ${accent}; color: #000; border: none; border-radius: 8px; padding: 0 20px; cursor: pointer; font-weight: 600; font-size: 14px; }
|
|
37
|
+
.chat-input button:hover { opacity: 0.85; }
|
|
38
|
+
.chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
39
|
+
</style>
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
<div class="chat-header">${title}</div>
|
|
43
|
+
<div class="chat-messages" id="messages"></div>
|
|
44
|
+
<div class="chat-input">
|
|
45
|
+
<textarea id="input" rows="1" placeholder="Type a message..." onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
|
|
46
|
+
<button id="sendBtn" onclick="sendMessage()">Send</button>
|
|
47
|
+
</div>
|
|
48
|
+
<script>
|
|
49
|
+
const ENDPOINT = ${JSON.stringify(endpoint)};
|
|
50
|
+
const messages = [];
|
|
51
|
+
const $msgs = document.getElementById('messages');
|
|
52
|
+
const $input = document.getElementById('input');
|
|
53
|
+
const $btn = document.getElementById('sendBtn');
|
|
54
|
+
|
|
55
|
+
function addMsg(role, text) {
|
|
56
|
+
const div = document.createElement('div');
|
|
57
|
+
div.className = 'msg ' + role;
|
|
58
|
+
div.textContent = text;
|
|
59
|
+
$msgs.appendChild(div);
|
|
60
|
+
$msgs.scrollTop = $msgs.scrollHeight;
|
|
61
|
+
return div;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function sendMessage() {
|
|
65
|
+
const text = $input.value.trim();
|
|
66
|
+
if (!text) return;
|
|
67
|
+
$input.value = '';
|
|
68
|
+
$btn.disabled = true;
|
|
69
|
+
messages.push({ role: 'user', content: text });
|
|
70
|
+
addMsg('user', text);
|
|
71
|
+
|
|
72
|
+
const div = addMsg('assistant', '');
|
|
73
|
+
div.classList.add('streaming');
|
|
74
|
+
let full = '';
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(ENDPOINT, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: { 'Content-Type': 'application/json' },
|
|
80
|
+
body: JSON.stringify({ messages }),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (res.headers.get('content-type')?.includes('text/event-stream')) {
|
|
84
|
+
const reader = res.body.getReader();
|
|
85
|
+
const decoder = new TextDecoder();
|
|
86
|
+
let buf = '';
|
|
87
|
+
while (true) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done) break;
|
|
90
|
+
buf += decoder.decode(value, { stream: true });
|
|
91
|
+
const lines = buf.split('\\n');
|
|
92
|
+
buf = lines.pop() || '';
|
|
93
|
+
for (const line of lines) {
|
|
94
|
+
if (line.startsWith('data: ')) {
|
|
95
|
+
const data = line.slice(6);
|
|
96
|
+
if (data === '[DONE]') break;
|
|
97
|
+
try { const j = JSON.parse(data); full += j.content || j.delta || ''; div.textContent = full; } catch {}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
$msgs.scrollTop = $msgs.scrollHeight;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
const data = await res.json();
|
|
104
|
+
full = data.content || data.message || JSON.stringify(data);
|
|
105
|
+
div.textContent = full;
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
full = 'Error: ' + e.message;
|
|
109
|
+
div.textContent = full;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
div.classList.remove('streaming');
|
|
113
|
+
messages.push({ role: 'assistant', content: full });
|
|
114
|
+
$btn.disabled = false;
|
|
115
|
+
$input.focus();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
$input.focus();
|
|
119
|
+
</script>
|
|
120
|
+
</body>
|
|
121
|
+
</html>`;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=components.js.map
|