@awi-protocol/react 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/.turbo/turbo-build.log +15 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +86 -0
- package/dist/index.mjs +60 -0
- package/package.json +36 -0
- package/src/index.ts +109 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$ tsup src/index.ts --format cjs,esm --dts --external react
|
|
2
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
3
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
4
|
+
[34mCLI[39m tsup v8.5.1
|
|
5
|
+
[34mCLI[39m Target: es2022
|
|
6
|
+
[34mCJS[39m Build start
|
|
7
|
+
[34mESM[39m Build start
|
|
8
|
+
[32mCJS[39m [1mdist\index.js [22m[32m2.73 KB[39m
|
|
9
|
+
[32mCJS[39m ⚡️ Build success in 30ms
|
|
10
|
+
[32mESM[39m [1mdist\index.mjs [22m[32m1.61 KB[39m
|
|
11
|
+
[32mESM[39m ⚡️ Build success in 30ms
|
|
12
|
+
[34mDTS[39m Build start
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 729ms
|
|
14
|
+
[32mDTS[39m [1mdist\index.d.ts [22m[32m1.28 KB[39m
|
|
15
|
+
[32mDTS[39m [1mdist\index.d.mts [22m[32m1.28 KB[39m
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AgentRequest, AgentResponse, AWIClientOptions } from '@awi-protocol/sdk';
|
|
2
|
+
export { AWIClient, AgentRequest, AgentResponse, Recipe, RegistryEntry } from '@awi-protocol/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React hooks for AWI
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useAWI } from '@awi-protocol/react';
|
|
10
|
+
*
|
|
11
|
+
* function JobSearch() {
|
|
12
|
+
* const { execute, loading, data, error } = useAWI({
|
|
13
|
+
* endpoint: 'https://awi.example.com',
|
|
14
|
+
* certificate: 'your-jwt',
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const search = async (query: string) => {
|
|
18
|
+
* await execute({
|
|
19
|
+
* target: 'awi://linkedin.com/jobs/search/v1',
|
|
20
|
+
* params: { query },
|
|
21
|
+
* });
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* {loading && <Spinner />}
|
|
27
|
+
* {error && <Error message={error.message} />}
|
|
28
|
+
* {data && <JobList jobs={data} />}
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
interface UseAWIResult<T = unknown> {
|
|
36
|
+
execute: (request: Omit<AgentRequest, 'mode'>) => Promise<AgentResponse<T>>;
|
|
37
|
+
explore: (domain: string, action: string) => Promise<AgentResponse<unknown>>;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
data: T | null;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
metrics: {
|
|
42
|
+
latency_ms: number;
|
|
43
|
+
fallback_count: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
46
|
+
declare function useAWI<T = unknown>(options: AWIClientOptions): UseAWIResult<T>;
|
|
47
|
+
|
|
48
|
+
export { type UseAWIResult, useAWI };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AgentRequest, AgentResponse, AWIClientOptions } from '@awi-protocol/sdk';
|
|
2
|
+
export { AWIClient, AgentRequest, AgentResponse, Recipe, RegistryEntry } from '@awi-protocol/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React hooks for AWI
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useAWI } from '@awi-protocol/react';
|
|
10
|
+
*
|
|
11
|
+
* function JobSearch() {
|
|
12
|
+
* const { execute, loading, data, error } = useAWI({
|
|
13
|
+
* endpoint: 'https://awi.example.com',
|
|
14
|
+
* certificate: 'your-jwt',
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const search = async (query: string) => {
|
|
18
|
+
* await execute({
|
|
19
|
+
* target: 'awi://linkedin.com/jobs/search/v1',
|
|
20
|
+
* params: { query },
|
|
21
|
+
* });
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* {loading && <Spinner />}
|
|
27
|
+
* {error && <Error message={error.message} />}
|
|
28
|
+
* {data && <JobList jobs={data} />}
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
interface UseAWIResult<T = unknown> {
|
|
36
|
+
execute: (request: Omit<AgentRequest, 'mode'>) => Promise<AgentResponse<T>>;
|
|
37
|
+
explore: (domain: string, action: string) => Promise<AgentResponse<unknown>>;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
data: T | null;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
metrics: {
|
|
42
|
+
latency_ms: number;
|
|
43
|
+
fallback_count: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
46
|
+
declare function useAWI<T = unknown>(options: AWIClientOptions): UseAWIResult<T>;
|
|
47
|
+
|
|
48
|
+
export { type UseAWIResult, useAWI };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AWIClient: () => import_sdk2.AWIClient,
|
|
24
|
+
useAWI: () => useAWI
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_sdk = require("@awi-protocol/sdk");
|
|
29
|
+
var import_sdk2 = require("@awi-protocol/sdk");
|
|
30
|
+
function useAWI(options) {
|
|
31
|
+
const [client] = (0, import_react.useState)(() => new import_sdk.AWIClient(options));
|
|
32
|
+
const [loading, setLoading] = (0, import_react.useState)(false);
|
|
33
|
+
const [data, setData] = (0, import_react.useState)(null);
|
|
34
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
35
|
+
const [metrics, setMetrics] = (0, import_react.useState)(null);
|
|
36
|
+
const execute = (0, import_react.useCallback)(async (request) => {
|
|
37
|
+
setLoading(true);
|
|
38
|
+
setError(null);
|
|
39
|
+
try {
|
|
40
|
+
const result = await client.execute(request);
|
|
41
|
+
if (result.success) {
|
|
42
|
+
setData(result.data);
|
|
43
|
+
} else {
|
|
44
|
+
setError(new Error(result.errors[0]?.message || "Execution failed"));
|
|
45
|
+
}
|
|
46
|
+
setMetrics({
|
|
47
|
+
latency_ms: result.metadata?.latency_ms || 0,
|
|
48
|
+
fallback_count: result.metadata?.fallback_count || 0
|
|
49
|
+
});
|
|
50
|
+
return result;
|
|
51
|
+
} catch (err) {
|
|
52
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
53
|
+
setError(error2);
|
|
54
|
+
throw error2;
|
|
55
|
+
} finally {
|
|
56
|
+
setLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}, [client]);
|
|
59
|
+
const explore = (0, import_react.useCallback)(async (domain, action) => {
|
|
60
|
+
setLoading(true);
|
|
61
|
+
setError(null);
|
|
62
|
+
try {
|
|
63
|
+
const result = await client.explore(domain, action);
|
|
64
|
+
return result;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
67
|
+
setError(error2);
|
|
68
|
+
throw error2;
|
|
69
|
+
} finally {
|
|
70
|
+
setLoading(false);
|
|
71
|
+
}
|
|
72
|
+
}, [client]);
|
|
73
|
+
return {
|
|
74
|
+
execute,
|
|
75
|
+
explore,
|
|
76
|
+
loading,
|
|
77
|
+
data,
|
|
78
|
+
error,
|
|
79
|
+
metrics
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
AWIClient,
|
|
85
|
+
useAWI
|
|
86
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
import { AWIClient } from "@awi-protocol/sdk";
|
|
4
|
+
import { AWIClient as AWIClient2 } from "@awi-protocol/sdk";
|
|
5
|
+
function useAWI(options) {
|
|
6
|
+
const [client] = useState(() => new AWIClient(options));
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const [metrics, setMetrics] = useState(null);
|
|
11
|
+
const execute = useCallback(async (request) => {
|
|
12
|
+
setLoading(true);
|
|
13
|
+
setError(null);
|
|
14
|
+
try {
|
|
15
|
+
const result = await client.execute(request);
|
|
16
|
+
if (result.success) {
|
|
17
|
+
setData(result.data);
|
|
18
|
+
} else {
|
|
19
|
+
setError(new Error(result.errors[0]?.message || "Execution failed"));
|
|
20
|
+
}
|
|
21
|
+
setMetrics({
|
|
22
|
+
latency_ms: result.metadata?.latency_ms || 0,
|
|
23
|
+
fallback_count: result.metadata?.fallback_count || 0
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
28
|
+
setError(error2);
|
|
29
|
+
throw error2;
|
|
30
|
+
} finally {
|
|
31
|
+
setLoading(false);
|
|
32
|
+
}
|
|
33
|
+
}, [client]);
|
|
34
|
+
const explore = useCallback(async (domain, action) => {
|
|
35
|
+
setLoading(true);
|
|
36
|
+
setError(null);
|
|
37
|
+
try {
|
|
38
|
+
const result = await client.explore(domain, action);
|
|
39
|
+
return result;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
42
|
+
setError(error2);
|
|
43
|
+
throw error2;
|
|
44
|
+
} finally {
|
|
45
|
+
setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [client]);
|
|
48
|
+
return {
|
|
49
|
+
execute,
|
|
50
|
+
explore,
|
|
51
|
+
loading,
|
|
52
|
+
data,
|
|
53
|
+
error,
|
|
54
|
+
metrics
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
AWIClient2 as AWIClient,
|
|
59
|
+
useAWI
|
|
60
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@awi-protocol/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React hooks for AWI (Agent Web Interface)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"awi",
|
|
14
|
+
"agent-web-interface",
|
|
15
|
+
"react",
|
|
16
|
+
"hooks",
|
|
17
|
+
"ai-agent",
|
|
18
|
+
"browser-automation"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@awi-protocol/sdk": "workspace:*"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^18.2.0",
|
|
31
|
+
"react": "^18.2.0",
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.3.0",
|
|
34
|
+
"vitest": "^1.2.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for AWI
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { useAWI } from '@awi-protocol/react';
|
|
7
|
+
*
|
|
8
|
+
* function JobSearch() {
|
|
9
|
+
* const { execute, loading, data, error } = useAWI({
|
|
10
|
+
* endpoint: 'https://awi.example.com',
|
|
11
|
+
* certificate: 'your-jwt',
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* const search = async (query: string) => {
|
|
15
|
+
* await execute({
|
|
16
|
+
* target: 'awi://linkedin.com/jobs/search/v1',
|
|
17
|
+
* params: { query },
|
|
18
|
+
* });
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <div>
|
|
23
|
+
* {loading && <Spinner />}
|
|
24
|
+
* {error && <Error message={error.message} />}
|
|
25
|
+
* {data && <JobList jobs={data} />}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { useState, useCallback } from 'react';
|
|
33
|
+
import { AWIClient, type AgentRequest, type AgentResponse, type AWIClientOptions } from '@awi-protocol/sdk';
|
|
34
|
+
|
|
35
|
+
export interface UseAWIResult<T = unknown> {
|
|
36
|
+
execute: (request: Omit<AgentRequest, 'mode'>) => Promise<AgentResponse<T>>;
|
|
37
|
+
explore: (domain: string, action: string) => Promise<AgentResponse<unknown>>;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
data: T | null;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
metrics: {
|
|
42
|
+
latency_ms: number;
|
|
43
|
+
fallback_count: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useAWI<T = unknown>(options: AWIClientOptions): UseAWIResult<T> {
|
|
48
|
+
const [client] = useState(() => new AWIClient(options));
|
|
49
|
+
const [loading, setLoading] = useState(false);
|
|
50
|
+
const [data, setData] = useState<T | null>(null);
|
|
51
|
+
const [error, setError] = useState<Error | null>(null);
|
|
52
|
+
const [metrics, setMetrics] = useState<UseAWIResult['metrics']>(null);
|
|
53
|
+
|
|
54
|
+
const execute = useCallback(async (request: Omit<AgentRequest, 'mode'>) => {
|
|
55
|
+
setLoading(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const result = await client.execute<T>(request);
|
|
60
|
+
|
|
61
|
+
if (result.success) {
|
|
62
|
+
setData(result.data);
|
|
63
|
+
} else {
|
|
64
|
+
setError(new Error(result.errors[0]?.message || 'Execution failed'));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setMetrics({
|
|
68
|
+
latency_ms: result.metadata?.latency_ms || 0,
|
|
69
|
+
fallback_count: (result.metadata?.fallback_count as number) || 0,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
75
|
+
setError(error);
|
|
76
|
+
throw error;
|
|
77
|
+
} finally {
|
|
78
|
+
setLoading(false);
|
|
79
|
+
}
|
|
80
|
+
}, [client]);
|
|
81
|
+
|
|
82
|
+
const explore = useCallback(async (domain: string, action: string) => {
|
|
83
|
+
setLoading(true);
|
|
84
|
+
setError(null);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const result = await client.explore(domain, action);
|
|
88
|
+
return result;
|
|
89
|
+
} catch (err) {
|
|
90
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
91
|
+
setError(error);
|
|
92
|
+
throw error;
|
|
93
|
+
} finally {
|
|
94
|
+
setLoading(false);
|
|
95
|
+
}
|
|
96
|
+
}, [client]);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
execute,
|
|
100
|
+
explore,
|
|
101
|
+
loading,
|
|
102
|
+
data,
|
|
103
|
+
error,
|
|
104
|
+
metrics,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { AWIClient } from '@awi-protocol/sdk';
|
|
109
|
+
export type { AgentRequest, AgentResponse, Recipe, RegistryEntry } from '@awi-protocol/sdk';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"noImplicitReturns": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"forceConsistentCasingInFileNames": true,
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"jsx": "react-jsx",
|
|
20
|
+
"outDir": "dist",
|
|
21
|
+
"rootDir": "src"
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"],
|
|
24
|
+
"exclude": ["node_modules", "dist"]
|
|
25
|
+
}
|