@economic/agents 0.0.1-alpha.8 → 0.0.1-beta.1
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 +553 -46
- package/dist/index.d.mts +116 -552
- package/dist/index.mjs +384 -471
- package/dist/react.d.mts +25 -0
- package/dist/react.mjs +38 -0
- package/package.json +24 -26
- package/schema/schema.sql +29 -0
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UIMessage } from "ai";
|
|
2
|
+
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
3
|
+
import { useAgent } from "agents/react";
|
|
4
|
+
|
|
5
|
+
//#region src/client/index.d.ts
|
|
6
|
+
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
7
|
+
interface UseAIChatAgentOptions {
|
|
8
|
+
agent: string;
|
|
9
|
+
host: string;
|
|
10
|
+
basePath?: string;
|
|
11
|
+
chatId: string;
|
|
12
|
+
toolContext?: Record<string, unknown>;
|
|
13
|
+
connectionParams?: Record<string, string>;
|
|
14
|
+
onConnectionStatusChange?: (status: AgentConnectionStatus) => void;
|
|
15
|
+
onOpen?: (event: Event) => void;
|
|
16
|
+
onClose?: (event: CloseEvent) => void;
|
|
17
|
+
onError?: (event: ErrorEvent) => void;
|
|
18
|
+
}
|
|
19
|
+
type UseAIChatAgentResult = {
|
|
20
|
+
agent: ReturnType<typeof useAgent>;
|
|
21
|
+
chat: ReturnType<typeof useAgentChat<unknown, UIMessage>>;
|
|
22
|
+
};
|
|
23
|
+
declare function useAIChatAgent(options: UseAIChatAgentOptions): UseAIChatAgentResult;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { AgentConnectionStatus, UseAIChatAgentOptions, useAIChatAgent };
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
2
|
+
import { useAgent } from "agents/react";
|
|
3
|
+
//#region src/client/index.ts
|
|
4
|
+
function useAIChatAgent(options) {
|
|
5
|
+
const { agent: agentName, host, basePath, chatId, toolContext, connectionParams, onConnectionStatusChange, onOpen: onOpenProp, onClose: onCloseProp, onError: onErrorProp } = options;
|
|
6
|
+
const agent = useAgent({
|
|
7
|
+
agent: agentName,
|
|
8
|
+
host,
|
|
9
|
+
basePath,
|
|
10
|
+
name: chatId,
|
|
11
|
+
query: connectionParams ?? {},
|
|
12
|
+
queryDeps: Object.keys(connectionParams ?? {}),
|
|
13
|
+
onOpen: (event) => {
|
|
14
|
+
onConnectionStatusChange?.("connected");
|
|
15
|
+
onOpenProp?.(event);
|
|
16
|
+
},
|
|
17
|
+
onClose: (event) => {
|
|
18
|
+
if (event.code >= 3e3) {
|
|
19
|
+
onConnectionStatusChange?.("unauthorized");
|
|
20
|
+
agent.close();
|
|
21
|
+
onCloseProp?.(event);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
onConnectionStatusChange?.("disconnected");
|
|
25
|
+
onCloseProp?.(event);
|
|
26
|
+
},
|
|
27
|
+
onError: onErrorProp
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
agent,
|
|
31
|
+
chat: useAgentChat({
|
|
32
|
+
agent,
|
|
33
|
+
body: toolContext ?? {}
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useAIChatAgent };
|
package/package.json
CHANGED
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
4
|
"description": "A starter for creating a TypeScript package.",
|
|
5
|
-
"homepage": "https://github.com/author/library#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/author/library/issues"
|
|
8
|
-
},
|
|
9
5
|
"license": "MIT",
|
|
10
|
-
"author": "Author Name <author.name@mail.com>",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/author/library.git"
|
|
14
|
-
},
|
|
15
6
|
"files": [
|
|
16
|
-
"dist"
|
|
7
|
+
"dist",
|
|
8
|
+
"schema"
|
|
17
9
|
],
|
|
18
10
|
"type": "module",
|
|
19
11
|
"exports": {
|
|
20
12
|
".": "./dist/index.mjs",
|
|
13
|
+
"./react": "./dist/react.mjs",
|
|
21
14
|
"./package.json": "./package.json"
|
|
22
15
|
},
|
|
23
16
|
"scripts": {
|
|
24
|
-
"build": "
|
|
25
|
-
"dev": "
|
|
26
|
-
"test": "
|
|
17
|
+
"build": "tsdown",
|
|
18
|
+
"dev": "tsdown --watch",
|
|
19
|
+
"test": "vitest",
|
|
27
20
|
"typecheck": "tsc --noEmit",
|
|
28
21
|
"release": "bumpp",
|
|
29
22
|
"prepublishOnly": "npm run build"
|
|
30
23
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@cloudflare/ai-chat": "^0.1.9",
|
|
33
|
-
"ai": "^6.0.116"
|
|
34
|
-
},
|
|
35
24
|
"devDependencies": {
|
|
25
|
+
"@cloudflare/ai-chat": "^0.1.9",
|
|
36
26
|
"@cloudflare/workers-types": "^4.20260317.1",
|
|
37
|
-
"@types/node": "^
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"@types/react": "^19.0.0",
|
|
38
29
|
"@typescript/native-preview": "7.0.0-dev.20260316.1",
|
|
30
|
+
"ai": "^6.0.134",
|
|
39
31
|
"bumpp": "^11.0.1",
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"tsdown": "^0.21.4",
|
|
40
34
|
"typescript": "^5.9.3",
|
|
41
|
-
"
|
|
42
|
-
|
|
35
|
+
"vitest": "^4.1.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@cloudflare/ai-chat": "^0.1.0",
|
|
39
|
+
"agents": "^0.7.6",
|
|
40
|
+
"ai": "^6.0.0",
|
|
41
|
+
"react": ">=18"
|
|
43
42
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"agents": "0.7.6"
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"react": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-- Full schema for @economic/agents.
|
|
2
|
+
-- One database per agent worker — create it once in the Cloudflare D1 portal.
|
|
3
|
+
-- Safe to re-run: all statements use IF NOT EXISTS.
|
|
4
|
+
|
|
5
|
+
-- ─── Audit events ─────────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
CREATE TABLE IF NOT EXISTS audit_events (
|
|
8
|
+
id TEXT PRIMARY KEY,
|
|
9
|
+
durable_object_name TEXT NOT NULL,
|
|
10
|
+
message TEXT NOT NULL,
|
|
11
|
+
payload TEXT,
|
|
12
|
+
created_at TEXT NOT NULL
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX IF NOT EXISTS audit_events_do ON audit_events(durable_object_name);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS audit_events_ts ON audit_events(created_at);
|
|
17
|
+
|
|
18
|
+
-- ─── Conversations ────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
CREATE TABLE IF NOT EXISTS conversations (
|
|
21
|
+
durable_object_name TEXT PRIMARY KEY,
|
|
22
|
+
title TEXT,
|
|
23
|
+
summary TEXT,
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
updated_at TEXT NOT NULL
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
CREATE INDEX IF NOT EXISTS conversations_do ON conversations(durable_object_name);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS conversations_ts ON conversations(updated_at);
|