agent-hustle-demo 1.0.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 +429 -0
- package/dist/HustleChat-BC9wvWVA.d.ts +90 -0
- package/dist/HustleChat-BcrKkkyn.d.cts +90 -0
- package/dist/browser/hustle-react.js +14854 -0
- package/dist/browser/hustle-react.js.map +1 -0
- package/dist/components/index.cjs +3141 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +20 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.js +3112 -0
- package/dist/components/index.js.map +1 -0
- package/dist/hooks/index.cjs +845 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +6 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +838 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hustle-Kj0X8qXC.d.cts +193 -0
- package/dist/hustle-Kj0X8qXC.d.ts +193 -0
- package/dist/index-ChUsRBwL.d.ts +152 -0
- package/dist/index-DE1N7C3W.d.cts +152 -0
- package/dist/index-DuPFrMZy.d.cts +214 -0
- package/dist/index-kFIdHjNw.d.ts +214 -0
- package/dist/index.cjs +3746 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +271 -0
- package/dist/index.d.ts +271 -0
- package/dist/index.js +3697 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.cjs +844 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +5 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +838 -0
- package/dist/providers/index.js.map +1 -0
- package/package.json +80 -0
- package/src/components/AuthStatus.tsx +352 -0
- package/src/components/ConnectButton.tsx +421 -0
- package/src/components/HustleChat.tsx +1273 -0
- package/src/components/MarkdownContent.tsx +431 -0
- package/src/components/index.ts +15 -0
- package/src/hooks/index.ts +40 -0
- package/src/hooks/useEmblemAuth.ts +27 -0
- package/src/hooks/useHustle.ts +36 -0
- package/src/hooks/usePlugins.ts +135 -0
- package/src/index.ts +142 -0
- package/src/plugins/index.ts +48 -0
- package/src/plugins/migrateFun.ts +211 -0
- package/src/plugins/predictionMarket.ts +411 -0
- package/src/providers/EmblemAuthProvider.tsx +319 -0
- package/src/providers/HustleProvider.tsx +540 -0
- package/src/providers/index.ts +6 -0
- package/src/styles/index.ts +2 -0
- package/src/styles/tokens.ts +447 -0
- package/src/types/auth.ts +85 -0
- package/src/types/hustle.ts +217 -0
- package/src/types/index.ts +49 -0
- package/src/types/plugin.ts +180 -0
- package/src/utils/index.ts +122 -0
- package/src/utils/pluginRegistry.ts +375 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import './index-ChUsRBwL.js';
|
|
2
|
+
import './hustle-Kj0X8qXC.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin Types for Hustle SDK
|
|
6
|
+
*
|
|
7
|
+
* These types define the plugin system that allows extending the AI
|
|
8
|
+
* with custom client-side tools.
|
|
9
|
+
*
|
|
10
|
+
* Executor functions are serialized as strings (executorCode) for localStorage
|
|
11
|
+
* persistence and reconstituted at runtime via new Function().
|
|
12
|
+
*
|
|
13
|
+
* SECURITY TODO: Add `signature` field to SerializedPlugin for cryptographic
|
|
14
|
+
* verification of plugin code before execution. This should use asymmetric
|
|
15
|
+
* signing (e.g., Ed25519) where plugins are signed by trusted publishers
|
|
16
|
+
* and verified before eval/Function execution.
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/verify
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* JSON Schema type for tool parameters
|
|
21
|
+
*/
|
|
22
|
+
interface JSONSchema {
|
|
23
|
+
type: 'object' | 'string' | 'number' | 'boolean' | 'array';
|
|
24
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
interface JSONSchemaProperty {
|
|
29
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
30
|
+
description?: string;
|
|
31
|
+
enum?: string[];
|
|
32
|
+
items?: JSONSchemaProperty;
|
|
33
|
+
default?: unknown;
|
|
34
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
35
|
+
required?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tool definition sent to server for AI registration
|
|
39
|
+
*/
|
|
40
|
+
interface ClientToolDefinition {
|
|
41
|
+
/** Unique tool name (used by AI to call the tool) */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Description of what the tool does (shown to AI) */
|
|
44
|
+
description: string;
|
|
45
|
+
/** JSON Schema for tool arguments */
|
|
46
|
+
parameters: JSONSchema;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Serialized tool definition (stored in localStorage)
|
|
50
|
+
* Contains executorCode as a string for persistence
|
|
51
|
+
*/
|
|
52
|
+
interface SerializedToolDefinition extends ClientToolDefinition {
|
|
53
|
+
/**
|
|
54
|
+
* Stringified executor function body for persistence.
|
|
55
|
+
* Reconstituted at runtime via new Function().
|
|
56
|
+
*
|
|
57
|
+
* FIXME: Add signature verification before execution
|
|
58
|
+
*/
|
|
59
|
+
executorCode?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Function that executes the tool client-side
|
|
63
|
+
*/
|
|
64
|
+
type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown>;
|
|
65
|
+
/**
|
|
66
|
+
* Request object passed to beforeRequest hook
|
|
67
|
+
*/
|
|
68
|
+
interface HustleRequest {
|
|
69
|
+
messages: Array<{
|
|
70
|
+
role: string;
|
|
71
|
+
content: string;
|
|
72
|
+
}>;
|
|
73
|
+
model?: string;
|
|
74
|
+
tools?: ClientToolDefinition[];
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Response object passed to afterResponse hook
|
|
79
|
+
*/
|
|
80
|
+
interface ProcessedResponse {
|
|
81
|
+
content: string;
|
|
82
|
+
toolCalls?: Array<{
|
|
83
|
+
toolCallId: string;
|
|
84
|
+
toolName: string;
|
|
85
|
+
args: Record<string, unknown>;
|
|
86
|
+
}>;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Error context passed to onError hook
|
|
91
|
+
*/
|
|
92
|
+
interface ErrorContext {
|
|
93
|
+
phase: 'request' | 'stream' | 'tool_execution';
|
|
94
|
+
toolName?: string;
|
|
95
|
+
args?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Plugin lifecycle hooks
|
|
99
|
+
*/
|
|
100
|
+
interface PluginHooks {
|
|
101
|
+
/** Called when plugin is registered */
|
|
102
|
+
onRegister?: () => void | Promise<void>;
|
|
103
|
+
/** Called before each request (can modify request) */
|
|
104
|
+
beforeRequest?: (req: HustleRequest) => HustleRequest | Promise<HustleRequest>;
|
|
105
|
+
/** Called after response is processed */
|
|
106
|
+
afterResponse?: (res: ProcessedResponse) => void | Promise<void>;
|
|
107
|
+
/** Called when an error occurs */
|
|
108
|
+
onError?: (error: Error, context: ErrorContext) => void | Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Serialized plugin hooks (stored in localStorage)
|
|
112
|
+
* Contains hook function bodies as strings for persistence
|
|
113
|
+
*
|
|
114
|
+
* FIXME: Add signature verification before execution
|
|
115
|
+
*/
|
|
116
|
+
interface SerializedHooks {
|
|
117
|
+
/** Stringified onRegister function */
|
|
118
|
+
onRegisterCode?: string;
|
|
119
|
+
/** Stringified beforeRequest function */
|
|
120
|
+
beforeRequestCode?: string;
|
|
121
|
+
/** Stringified afterResponse function */
|
|
122
|
+
afterResponseCode?: string;
|
|
123
|
+
/** Stringified onError function */
|
|
124
|
+
onErrorCode?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Plugin definition
|
|
128
|
+
*/
|
|
129
|
+
interface HustlePlugin {
|
|
130
|
+
/** Unique plugin identifier */
|
|
131
|
+
name: string;
|
|
132
|
+
/** Semantic version */
|
|
133
|
+
version: string;
|
|
134
|
+
/** Optional description */
|
|
135
|
+
description?: string;
|
|
136
|
+
/** Tool schemas sent to server for AI registration */
|
|
137
|
+
tools?: ClientToolDefinition[];
|
|
138
|
+
/** Local execution functions (keyed by tool name) */
|
|
139
|
+
executors?: Record<string, ToolExecutor>;
|
|
140
|
+
/** Lifecycle hooks */
|
|
141
|
+
hooks?: PluginHooks;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin with enabled state (stored in localStorage)
|
|
145
|
+
* Tools include executorCode for function persistence
|
|
146
|
+
*
|
|
147
|
+
* FIXME: Add `signature?: string` for cryptographic verification
|
|
148
|
+
*/
|
|
149
|
+
interface StoredPlugin {
|
|
150
|
+
/** Unique plugin identifier */
|
|
151
|
+
name: string;
|
|
152
|
+
/** Semantic version */
|
|
153
|
+
version: string;
|
|
154
|
+
/** Optional description */
|
|
155
|
+
description?: string;
|
|
156
|
+
/** Tool schemas with serialized executorCode */
|
|
157
|
+
tools?: SerializedToolDefinition[];
|
|
158
|
+
/** Serialized lifecycle hooks */
|
|
159
|
+
hooksCode?: SerializedHooks;
|
|
160
|
+
/** Whether the plugin is enabled */
|
|
161
|
+
enabled: boolean;
|
|
162
|
+
/** Timestamp when plugin was installed */
|
|
163
|
+
installedAt?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Plugin with hydrated executors (ready for use)
|
|
167
|
+
*/
|
|
168
|
+
interface HydratedPlugin extends StoredPlugin {
|
|
169
|
+
/** Restored executor functions */
|
|
170
|
+
executors?: Record<string, ToolExecutor>;
|
|
171
|
+
/** Restored hooks */
|
|
172
|
+
hooks?: PluginHooks;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Return type for usePlugins hook
|
|
177
|
+
*/
|
|
178
|
+
interface UsePluginsReturn {
|
|
179
|
+
/** All registered plugins (with enabled state) */
|
|
180
|
+
plugins: StoredPlugin[];
|
|
181
|
+
/** Only enabled plugins (hydrated with executors) */
|
|
182
|
+
enabledPlugins: HydratedPlugin[];
|
|
183
|
+
/** Register a new plugin */
|
|
184
|
+
registerPlugin: (plugin: HustlePlugin) => void;
|
|
185
|
+
/** Unregister a plugin by name */
|
|
186
|
+
unregisterPlugin: (name: string) => void;
|
|
187
|
+
/** Enable a plugin */
|
|
188
|
+
enablePlugin: (name: string) => void;
|
|
189
|
+
/** Disable a plugin */
|
|
190
|
+
disablePlugin: (name: string) => void;
|
|
191
|
+
/** Check if a plugin is registered */
|
|
192
|
+
isRegistered: (name: string) => boolean;
|
|
193
|
+
/** Check if a plugin is enabled */
|
|
194
|
+
isEnabled: (name: string) => boolean;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Hook for managing plugins
|
|
198
|
+
*
|
|
199
|
+
* @param instanceId - Optional instance ID for scoping plugin storage (defaults to 'default')
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* const { plugins, registerPlugin, enabledPlugins } = usePlugins();
|
|
204
|
+
*
|
|
205
|
+
* // Install a plugin
|
|
206
|
+
* registerPlugin(myPlugin);
|
|
207
|
+
*
|
|
208
|
+
* // Check enabled plugins
|
|
209
|
+
* console.log('Active tools:', enabledPlugins.flatMap(p => p.tools));
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare function usePlugins(instanceId?: string): UsePluginsReturn;
|
|
213
|
+
|
|
214
|
+
export { type ClientToolDefinition as C, type ErrorContext as E, type HustlePlugin as H, type JSONSchema as J, type ProcessedResponse as P, type StoredPlugin as S, type ToolExecutor as T, type UsePluginsReturn as U, type HydratedPlugin as a, type JSONSchemaProperty as b, type SerializedToolDefinition as c, type HustleRequest as d, type PluginHooks as e, type SerializedHooks as f, usePlugins as u };
|