@27works/chat-core 0.1.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 +776 -0
- package/dist/components/index.d.ts +18 -0
- package/dist/components/index.js +609 -0
- package/dist/contexts/index.d.ts +11 -0
- package/dist/contexts/index.js +175 -0
- package/dist/hooks/index.d.ts +76 -0
- package/dist/hooks/index.js +406 -0
- package/dist/server/index.d.ts +227 -0
- package/dist/server/index.js +15561 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +56 -0
- package/package.json +72 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ToolSet, UIMessage, UIDataTypes, InferUITools } from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build a HumanInTheLoopUIMessage type for a given tools definition.
|
|
5
|
+
* Each app supplies its own tools type; this utility wraps the AI SDK's UIMessage.
|
|
6
|
+
*/
|
|
7
|
+
type HumanInTheLoopUIMessage<T extends ToolSet = ToolSet> = UIMessage<never, UIDataTypes, InferUITools<T>>;
|
|
8
|
+
|
|
9
|
+
export type { HumanInTheLoopUIMessage };
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ToolSet } from 'ai';
|
|
2
|
+
|
|
3
|
+
declare function getOrCreateAnonymousId(): string;
|
|
4
|
+
|
|
5
|
+
declare function trackLinkClick({ conversationId, url, linkLabel, messageIndex }: {
|
|
6
|
+
conversationId: any;
|
|
7
|
+
url: any;
|
|
8
|
+
linkLabel: any;
|
|
9
|
+
messageIndex: any;
|
|
10
|
+
}): void;
|
|
11
|
+
|
|
12
|
+
declare const APPROVAL: {
|
|
13
|
+
readonly YES: "Yes, confirmed.";
|
|
14
|
+
readonly NO: "No, denied.";
|
|
15
|
+
};
|
|
16
|
+
declare function getToolsRequiringConfirmation<T extends ToolSet>(tools: T): string[];
|
|
17
|
+
declare function cn(...inputs: any[]): string;
|
|
18
|
+
|
|
19
|
+
export { APPROVAL, cn, getOrCreateAnonymousId, getToolsRequiringConfirmation, trackLinkClick };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/utils/index.ts
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
|
|
5
|
+
// src/utils/anonymousId.js
|
|
6
|
+
var STORAGE_KEY = "caruuto_anonymous_id";
|
|
7
|
+
function getOrCreateAnonymousId() {
|
|
8
|
+
try {
|
|
9
|
+
const existing = window.localStorage.getItem(STORAGE_KEY);
|
|
10
|
+
if (existing) {
|
|
11
|
+
return existing;
|
|
12
|
+
}
|
|
13
|
+
const id = crypto.randomUUID();
|
|
14
|
+
window.localStorage.setItem(STORAGE_KEY, id);
|
|
15
|
+
return id;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error("Failed to get or create anonymous ID:", err);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/utils/linkClickTracking.js
|
|
23
|
+
var ENDPOINT = "/api/chat/link-click";
|
|
24
|
+
function trackLinkClick({ conversationId, url, linkLabel, messageIndex }) {
|
|
25
|
+
if (!conversationId || !url) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const payload = JSON.stringify({ conversationId, url, linkLabel, messageIndex });
|
|
30
|
+
navigator.sendBeacon(ENDPOINT, new Blob([payload], { type: "application/json" }));
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error("Failed to dispatch link click event:", err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/utils/index.ts
|
|
37
|
+
var APPROVAL = {
|
|
38
|
+
YES: "Yes, confirmed.",
|
|
39
|
+
NO: "No, denied."
|
|
40
|
+
};
|
|
41
|
+
function getToolsRequiringConfirmation(tools) {
|
|
42
|
+
return Object.keys(tools).filter((key) => {
|
|
43
|
+
const maybeTool = tools[key];
|
|
44
|
+
return typeof maybeTool.execute !== "function";
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function cn(...inputs) {
|
|
48
|
+
return twMerge(clsx(inputs));
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
APPROVAL,
|
|
52
|
+
cn,
|
|
53
|
+
getOrCreateAnonymousId,
|
|
54
|
+
getToolsRequiringConfirmation,
|
|
55
|
+
trackLinkClick
|
|
56
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@27works/chat-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core utilities and components for 27works chat applications.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/27Works/chat-core.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": "https://github.com/27Works/chat-core/issues",
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
|
+
"author": "Jim Lambie <jim@27.works>",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./dist/server/index.d.ts",
|
|
19
|
+
"default": "./dist/server/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./hooks": {
|
|
22
|
+
"types": "./dist/hooks/index.d.ts",
|
|
23
|
+
"default": "./dist/hooks/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./contexts": {
|
|
26
|
+
"types": "./dist/contexts/index.d.ts",
|
|
27
|
+
"default": "./dist/contexts/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./components": {
|
|
30
|
+
"types": "./dist/components/index.d.ts",
|
|
31
|
+
"default": "./dist/components/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./types": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"default": "./dist/types/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./utils": {
|
|
38
|
+
"types": "./dist/utils/index.d.ts",
|
|
39
|
+
"default": "./dist/utils/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"lint": "eslint src",
|
|
45
|
+
"prepublishOnly": "npm run build"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@ai-sdk/openai": ">=3",
|
|
49
|
+
"@ai-sdk/react": ">=3",
|
|
50
|
+
"@caruuto/caruuto-js": ">=0.9.1",
|
|
51
|
+
"@supabase/supabase-js": ">=2",
|
|
52
|
+
"@upstash/ratelimit": ">=2",
|
|
53
|
+
"@upstash/redis": ">=1",
|
|
54
|
+
"ai": ">=6",
|
|
55
|
+
"clsx": ">=2",
|
|
56
|
+
"next": ">=15",
|
|
57
|
+
"react": ">=19",
|
|
58
|
+
"server-only": "*",
|
|
59
|
+
"tailwind-merge": ">=3"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/js": "^9",
|
|
63
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
64
|
+
"eslint": "^9",
|
|
65
|
+
"eslint-plugin-import": "^2.32.0",
|
|
66
|
+
"eslint-plugin-react": "^7",
|
|
67
|
+
"eslint-plugin-react-hooks": "^7",
|
|
68
|
+
"globals": "^16",
|
|
69
|
+
"tsup": "^8.5.1",
|
|
70
|
+
"typescript": "^5"
|
|
71
|
+
}
|
|
72
|
+
}
|