agenauto-nextjs 1.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 ADDED
@@ -0,0 +1,81 @@
1
+ # @agenauto/nextjs
2
+
3
+ Official Next.js SDK for [AgenAuto](https://agenauto.dev) — your autonomous AI agent.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agenauto/nextjs
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Add the Provider
14
+
15
+ Wrap your app with the `AgenAutoProvider` in your root layout:
16
+
17
+ ```tsx
18
+ // app/layout.tsx
19
+ import { AgenAutoProvider } from '@agenauto/nextjs';
20
+
21
+ export default function RootLayout({ children }) {
22
+ return (
23
+ <html>
24
+ <body>
25
+ <AgenAutoProvider agentKey="YOUR_AGENT_KEY">
26
+ {children}
27
+ </AgenAutoProvider>
28
+ </body>
29
+ </html>
30
+ );
31
+ }
32
+ ```
33
+
34
+ ### 2. Use the Hook (Optional)
35
+
36
+ Interact with your agent programmatically:
37
+
38
+ ```tsx
39
+ 'use client';
40
+ import { useAgenAuto } from '@agenauto/nextjs';
41
+
42
+ function MyComponent() {
43
+ const { status, sendMessage } = useAgenAuto();
44
+
45
+ const askAgent = async () => {
46
+ const response = await sendMessage('Analyze this page for SEO');
47
+ console.log(response.reply);
48
+ };
49
+
50
+ return (
51
+ <div>
52
+ <p>Agent: {status.connected ? '🟢 Connected' : '🔴 Disconnected'}</p>
53
+ <button onClick={askAgent}>Ask Agent</button>
54
+ </div>
55
+ );
56
+ }
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `<AgenAutoProvider>`
62
+
63
+ | Prop | Type | Default | Description |
64
+ |:---|:---|:---|:---|
65
+ | `agentKey` | `string` | **required** | Your Agent Key from the AgenAuto dashboard |
66
+ | `apiUrl` | `string` | `https://app.agenauto.dev` | Your AgenAuto instance URL |
67
+ | `showBadge` | `boolean` | `false` | Show status badge on the page |
68
+
69
+ ### `useAgenAuto()`
70
+
71
+ Returns:
72
+
73
+ | Property | Type | Description |
74
+ |:---|:---|:---|
75
+ | `status` | `AgentStatus` | `{ connected, agentName, model }` |
76
+ | `sendMessage` | `(msg: string) => Promise` | Send a message to your agent |
77
+ | `reportPage` | `() => void` | Manually report current page data |
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ interface AgenAutoConfig {
4
+ agentKey: string;
5
+ apiUrl?: string;
6
+ showBadge?: boolean;
7
+ }
8
+ interface AgentStatus {
9
+ connected: boolean;
10
+ agentName?: string;
11
+ model?: string;
12
+ }
13
+ interface AgenAutoContextValue {
14
+ status: AgentStatus;
15
+ sendMessage: (message: string) => Promise<{
16
+ reply: string;
17
+ tools_used: string[];
18
+ iterations: number;
19
+ tokens: number;
20
+ }>;
21
+ reportPage: () => void;
22
+ }
23
+ interface ProviderProps extends AgenAutoConfig {
24
+ children: React.ReactNode;
25
+ }
26
+ declare function AgenAutoProvider({ agentKey, apiUrl, showBadge, children }: ProviderProps): React.FunctionComponentElement<React.ProviderProps<AgenAutoContextValue | null>>;
27
+ declare function useAgenAuto(): AgenAutoContextValue;
28
+
29
+ export { type AgenAutoConfig, type AgenAutoContextValue, AgenAutoProvider, type AgentStatus, useAgenAuto };
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ interface AgenAutoConfig {
4
+ agentKey: string;
5
+ apiUrl?: string;
6
+ showBadge?: boolean;
7
+ }
8
+ interface AgentStatus {
9
+ connected: boolean;
10
+ agentName?: string;
11
+ model?: string;
12
+ }
13
+ interface AgenAutoContextValue {
14
+ status: AgentStatus;
15
+ sendMessage: (message: string) => Promise<{
16
+ reply: string;
17
+ tools_used: string[];
18
+ iterations: number;
19
+ tokens: number;
20
+ }>;
21
+ reportPage: () => void;
22
+ }
23
+ interface ProviderProps extends AgenAutoConfig {
24
+ children: React.ReactNode;
25
+ }
26
+ declare function AgenAutoProvider({ agentKey, apiUrl, showBadge, children }: ProviderProps): React.FunctionComponentElement<React.ProviderProps<AgenAutoContextValue | null>>;
27
+ declare function useAgenAuto(): AgenAutoContextValue;
28
+
29
+ export { type AgenAutoConfig, type AgenAutoContextValue, AgenAutoProvider, type AgentStatus, useAgenAuto };
package/dist/index.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ AgenAutoProvider: () => AgenAutoProvider,
35
+ useAgenAuto: () => useAgenAuto
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_react = __toESM(require("react"));
39
+ var AgenAutoContext = (0, import_react.createContext)(null);
40
+ function AgenAutoProvider({ agentKey, apiUrl = "https://app.agenauto.dev", showBadge = false, children }) {
41
+ const [status, setStatus] = (0, import_react.useState)({ connected: false });
42
+ const apiBaseRef = (0, import_react.useRef)(apiUrl);
43
+ (0, import_react.useEffect)(() => {
44
+ apiBaseRef.current = apiUrl;
45
+ fetch(`${apiUrl}/api/v1/status`, {
46
+ headers: { Authorization: `Bearer ${agentKey}` }
47
+ }).then((res) => res.json()).then((data) => {
48
+ if (data.agent) {
49
+ setStatus({
50
+ connected: true,
51
+ agentName: data.agent.name,
52
+ model: data.agent.model
53
+ });
54
+ console.log(`AgenAuto: Connected \u2713 (Agent: ${data.agent.name})`);
55
+ }
56
+ }).catch(() => {
57
+ console.warn("AgenAuto: Connection failed. Check your agent key.");
58
+ });
59
+ }, [agentKey, apiUrl]);
60
+ const reportPage = (0, import_react.useCallback)(() => {
61
+ const data = {
62
+ url: window.location.href,
63
+ title: document.title,
64
+ referrer: document.referrer,
65
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
66
+ };
67
+ fetch(`${apiBaseRef.current}/api/v1/report`, {
68
+ method: "POST",
69
+ headers: {
70
+ "Content-Type": "application/json",
71
+ Authorization: `Bearer ${agentKey}`
72
+ },
73
+ body: JSON.stringify({ agentKey, type: "nextjs_page_report", data })
74
+ }).catch(() => {
75
+ });
76
+ }, [agentKey]);
77
+ (0, import_react.useEffect)(() => {
78
+ reportPage();
79
+ }, [reportPage]);
80
+ const sendMessage = (0, import_react.useCallback)(
81
+ async (message) => {
82
+ const res = await fetch(`${apiBaseRef.current}/api/v1/chat`, {
83
+ method: "POST",
84
+ headers: {
85
+ "Content-Type": "application/json",
86
+ Authorization: `Bearer ${agentKey}`
87
+ },
88
+ body: JSON.stringify({ agentKey, message })
89
+ });
90
+ if (!res.ok) {
91
+ const err = await res.json().catch(() => ({ error: "Request failed" }));
92
+ throw new Error(err.error || "Request failed");
93
+ }
94
+ return res.json();
95
+ },
96
+ [agentKey]
97
+ );
98
+ const value = { status, sendMessage, reportPage };
99
+ return import_react.default.createElement(AgenAutoContext.Provider, { value }, children);
100
+ }
101
+ function useAgenAuto() {
102
+ const context = (0, import_react.useContext)(AgenAutoContext);
103
+ if (!context) {
104
+ throw new Error("useAgenAuto must be used within an AgenAutoProvider");
105
+ }
106
+ return context;
107
+ }
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ AgenAutoProvider,
111
+ useAgenAuto
112
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ // src/index.ts
4
+ import React, { createContext, useContext, useEffect, useRef, useState, useCallback } from "react";
5
+ var AgenAutoContext = createContext(null);
6
+ function AgenAutoProvider({ agentKey, apiUrl = "https://app.agenauto.dev", showBadge = false, children }) {
7
+ const [status, setStatus] = useState({ connected: false });
8
+ const apiBaseRef = useRef(apiUrl);
9
+ useEffect(() => {
10
+ apiBaseRef.current = apiUrl;
11
+ fetch(`${apiUrl}/api/v1/status`, {
12
+ headers: { Authorization: `Bearer ${agentKey}` }
13
+ }).then((res) => res.json()).then((data) => {
14
+ if (data.agent) {
15
+ setStatus({
16
+ connected: true,
17
+ agentName: data.agent.name,
18
+ model: data.agent.model
19
+ });
20
+ console.log(`AgenAuto: Connected \u2713 (Agent: ${data.agent.name})`);
21
+ }
22
+ }).catch(() => {
23
+ console.warn("AgenAuto: Connection failed. Check your agent key.");
24
+ });
25
+ }, [agentKey, apiUrl]);
26
+ const reportPage = useCallback(() => {
27
+ const data = {
28
+ url: window.location.href,
29
+ title: document.title,
30
+ referrer: document.referrer,
31
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
32
+ };
33
+ fetch(`${apiBaseRef.current}/api/v1/report`, {
34
+ method: "POST",
35
+ headers: {
36
+ "Content-Type": "application/json",
37
+ Authorization: `Bearer ${agentKey}`
38
+ },
39
+ body: JSON.stringify({ agentKey, type: "nextjs_page_report", data })
40
+ }).catch(() => {
41
+ });
42
+ }, [agentKey]);
43
+ useEffect(() => {
44
+ reportPage();
45
+ }, [reportPage]);
46
+ const sendMessage = useCallback(
47
+ async (message) => {
48
+ const res = await fetch(`${apiBaseRef.current}/api/v1/chat`, {
49
+ method: "POST",
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ Authorization: `Bearer ${agentKey}`
53
+ },
54
+ body: JSON.stringify({ agentKey, message })
55
+ });
56
+ if (!res.ok) {
57
+ const err = await res.json().catch(() => ({ error: "Request failed" }));
58
+ throw new Error(err.error || "Request failed");
59
+ }
60
+ return res.json();
61
+ },
62
+ [agentKey]
63
+ );
64
+ const value = { status, sendMessage, reportPage };
65
+ return React.createElement(AgenAutoContext.Provider, { value }, children);
66
+ }
67
+ function useAgenAuto() {
68
+ const context = useContext(AgenAutoContext);
69
+ if (!context) {
70
+ throw new Error("useAgenAuto must be used within an AgenAutoProvider");
71
+ }
72
+ return context;
73
+ }
74
+ export {
75
+ AgenAutoProvider,
76
+ useAgenAuto
77
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "agenauto-nextjs",
3
+ "version": "1.0.0",
4
+ "description": "AgenAuto SDK for Next.js — connect your React app to your autonomous AI agent",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format cjs,esm --dts",
13
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
14
+ },
15
+ "peerDependencies": {
16
+ "react": ">=18.0.0",
17
+ "react-dom": ">=18.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "react": "^19.0.0",
21
+ "react-dom": "^19.0.0",
22
+ "tsup": "^8.0.0",
23
+ "typescript": "^5.0.0"
24
+ },
25
+ "keywords": [
26
+ "agenauto",
27
+ "ai",
28
+ "agent",
29
+ "nextjs",
30
+ "react",
31
+ "seo",
32
+ "optimization"
33
+ ],
34
+ "author": "AgenAuto <hello@agenauto.dev>",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/agenauto/nextjs-sdk"
39
+ }
40
+ }