@emblemvault/hustle-react 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.
Files changed (38) hide show
  1. package/README.md +225 -0
  2. package/dist/browser/hustle-react.js +14705 -0
  3. package/dist/browser/hustle-react.js.map +1 -0
  4. package/dist/components/index.cjs +3170 -0
  5. package/dist/components/index.cjs.map +1 -0
  6. package/dist/components/index.d.cts +58 -0
  7. package/dist/components/index.d.ts +58 -0
  8. package/dist/components/index.js +3143 -0
  9. package/dist/components/index.js.map +1 -0
  10. package/dist/hooks/index.cjs +695 -0
  11. package/dist/hooks/index.cjs.map +1 -0
  12. package/dist/hooks/index.d.cts +46 -0
  13. package/dist/hooks/index.d.ts +46 -0
  14. package/dist/hooks/index.js +691 -0
  15. package/dist/hooks/index.js.map +1 -0
  16. package/dist/hustle-S48t4lTZ.d.cts +222 -0
  17. package/dist/hustle-S48t4lTZ.d.ts +222 -0
  18. package/dist/index.cjs +3588 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +229 -0
  21. package/dist/index.d.ts +229 -0
  22. package/dist/index.js +3547 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/plugin-BUg7vMxe.d.cts +172 -0
  25. package/dist/plugin-BUg7vMxe.d.ts +172 -0
  26. package/dist/plugins/index.cjs +1235 -0
  27. package/dist/plugins/index.cjs.map +1 -0
  28. package/dist/plugins/index.d.cts +192 -0
  29. package/dist/plugins/index.d.ts +192 -0
  30. package/dist/plugins/index.js +1225 -0
  31. package/dist/plugins/index.js.map +1 -0
  32. package/dist/providers/index.cjs +694 -0
  33. package/dist/providers/index.cjs.map +1 -0
  34. package/dist/providers/index.d.cts +46 -0
  35. package/dist/providers/index.d.ts +46 -0
  36. package/dist/providers/index.js +691 -0
  37. package/dist/providers/index.js.map +1 -0
  38. package/package.json +87 -0
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Plugin Types for Hustle SDK
3
+ *
4
+ * These types define the plugin system that allows extending the AI
5
+ * with custom client-side tools.
6
+ *
7
+ * Executor functions are serialized as strings (executorCode) for localStorage
8
+ * persistence and reconstituted at runtime via new Function().
9
+ *
10
+ * SECURITY TODO: Add `signature` field to SerializedPlugin for cryptographic
11
+ * verification of plugin code before execution. This should use asymmetric
12
+ * signing (e.g., Ed25519) where plugins are signed by trusted publishers
13
+ * and verified before eval/Function execution.
14
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/verify
15
+ */
16
+ /**
17
+ * JSON Schema type for tool parameters
18
+ */
19
+ interface JSONSchema {
20
+ type: 'object' | 'string' | 'number' | 'boolean' | 'array';
21
+ properties?: Record<string, JSONSchemaProperty>;
22
+ required?: string[];
23
+ description?: string;
24
+ }
25
+ interface JSONSchemaProperty {
26
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
27
+ description?: string;
28
+ enum?: string[];
29
+ items?: JSONSchemaProperty;
30
+ default?: unknown;
31
+ properties?: Record<string, JSONSchemaProperty>;
32
+ required?: string[];
33
+ }
34
+ /**
35
+ * Tool definition sent to server for AI registration
36
+ */
37
+ interface ClientToolDefinition {
38
+ /** Unique tool name (used by AI to call the tool) */
39
+ name: string;
40
+ /** Description of what the tool does (shown to AI) */
41
+ description: string;
42
+ /** JSON Schema for tool arguments */
43
+ parameters: JSONSchema;
44
+ }
45
+ /**
46
+ * Serialized tool definition (stored in localStorage)
47
+ * Contains executorCode as a string for persistence
48
+ */
49
+ interface SerializedToolDefinition extends ClientToolDefinition {
50
+ /**
51
+ * Stringified executor function body for persistence.
52
+ * Reconstituted at runtime via new Function().
53
+ *
54
+ * FIXME: Add signature verification before execution
55
+ */
56
+ executorCode?: string;
57
+ }
58
+ /**
59
+ * Function that executes the tool client-side
60
+ */
61
+ type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown>;
62
+ /**
63
+ * Request object passed to beforeRequest hook
64
+ */
65
+ interface HustleRequest {
66
+ messages: Array<{
67
+ role: string;
68
+ content: string;
69
+ }>;
70
+ model?: string;
71
+ tools?: ClientToolDefinition[];
72
+ [key: string]: unknown;
73
+ }
74
+ /**
75
+ * Response object passed to afterResponse hook
76
+ */
77
+ interface ProcessedResponse {
78
+ content: string;
79
+ toolCalls?: Array<{
80
+ toolCallId: string;
81
+ toolName: string;
82
+ args: Record<string, unknown>;
83
+ }>;
84
+ [key: string]: unknown;
85
+ }
86
+ /**
87
+ * Error context passed to onError hook
88
+ */
89
+ interface ErrorContext {
90
+ phase: 'request' | 'stream' | 'tool_execution';
91
+ toolName?: string;
92
+ args?: Record<string, unknown>;
93
+ }
94
+ /**
95
+ * Plugin lifecycle hooks
96
+ */
97
+ interface PluginHooks {
98
+ /** Called when plugin is registered */
99
+ onRegister?: () => void | Promise<void>;
100
+ /** Called before each request (can modify request) */
101
+ beforeRequest?: (req: HustleRequest) => HustleRequest | Promise<HustleRequest>;
102
+ /** Called after response is processed */
103
+ afterResponse?: (res: ProcessedResponse) => void | Promise<void>;
104
+ /** Called when an error occurs */
105
+ onError?: (error: Error, context: ErrorContext) => void | Promise<void>;
106
+ }
107
+ /**
108
+ * Serialized plugin hooks (stored in localStorage)
109
+ * Contains hook function bodies as strings for persistence
110
+ *
111
+ * FIXME: Add signature verification before execution
112
+ */
113
+ interface SerializedHooks {
114
+ /** Stringified onRegister function */
115
+ onRegisterCode?: string;
116
+ /** Stringified beforeRequest function */
117
+ beforeRequestCode?: string;
118
+ /** Stringified afterResponse function */
119
+ afterResponseCode?: string;
120
+ /** Stringified onError function */
121
+ onErrorCode?: string;
122
+ }
123
+ /**
124
+ * Plugin definition
125
+ */
126
+ interface HustlePlugin {
127
+ /** Unique plugin identifier */
128
+ name: string;
129
+ /** Semantic version */
130
+ version: string;
131
+ /** Optional description */
132
+ description?: string;
133
+ /** Tool schemas sent to server for AI registration */
134
+ tools?: ClientToolDefinition[];
135
+ /** Local execution functions (keyed by tool name) */
136
+ executors?: Record<string, ToolExecutor>;
137
+ /** Lifecycle hooks */
138
+ hooks?: PluginHooks;
139
+ }
140
+ /**
141
+ * Plugin with enabled state (stored in localStorage)
142
+ * Tools include executorCode for function persistence
143
+ *
144
+ * FIXME: Add `signature?: string` for cryptographic verification
145
+ */
146
+ interface StoredPlugin {
147
+ /** Unique plugin identifier */
148
+ name: string;
149
+ /** Semantic version */
150
+ version: string;
151
+ /** Optional description */
152
+ description?: string;
153
+ /** Tool schemas with serialized executorCode */
154
+ tools?: SerializedToolDefinition[];
155
+ /** Serialized lifecycle hooks */
156
+ hooksCode?: SerializedHooks;
157
+ /** Whether the plugin is enabled */
158
+ enabled: boolean;
159
+ /** Timestamp when plugin was installed */
160
+ installedAt?: string;
161
+ }
162
+ /**
163
+ * Plugin with hydrated executors (ready for use)
164
+ */
165
+ interface HydratedPlugin extends StoredPlugin {
166
+ /** Restored executor functions */
167
+ executors?: Record<string, ToolExecutor>;
168
+ /** Restored hooks */
169
+ hooks?: PluginHooks;
170
+ }
171
+
172
+ export type { ClientToolDefinition as C, ErrorContext as E, HustlePlugin as H, JSONSchema as J, ProcessedResponse as P, StoredPlugin as S, ToolExecutor as T, HydratedPlugin as a, JSONSchemaProperty as b, SerializedToolDefinition as c, HustleRequest as d, PluginHooks as e, SerializedHooks as f };
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Plugin Types for Hustle SDK
3
+ *
4
+ * These types define the plugin system that allows extending the AI
5
+ * with custom client-side tools.
6
+ *
7
+ * Executor functions are serialized as strings (executorCode) for localStorage
8
+ * persistence and reconstituted at runtime via new Function().
9
+ *
10
+ * SECURITY TODO: Add `signature` field to SerializedPlugin for cryptographic
11
+ * verification of plugin code before execution. This should use asymmetric
12
+ * signing (e.g., Ed25519) where plugins are signed by trusted publishers
13
+ * and verified before eval/Function execution.
14
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/verify
15
+ */
16
+ /**
17
+ * JSON Schema type for tool parameters
18
+ */
19
+ interface JSONSchema {
20
+ type: 'object' | 'string' | 'number' | 'boolean' | 'array';
21
+ properties?: Record<string, JSONSchemaProperty>;
22
+ required?: string[];
23
+ description?: string;
24
+ }
25
+ interface JSONSchemaProperty {
26
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
27
+ description?: string;
28
+ enum?: string[];
29
+ items?: JSONSchemaProperty;
30
+ default?: unknown;
31
+ properties?: Record<string, JSONSchemaProperty>;
32
+ required?: string[];
33
+ }
34
+ /**
35
+ * Tool definition sent to server for AI registration
36
+ */
37
+ interface ClientToolDefinition {
38
+ /** Unique tool name (used by AI to call the tool) */
39
+ name: string;
40
+ /** Description of what the tool does (shown to AI) */
41
+ description: string;
42
+ /** JSON Schema for tool arguments */
43
+ parameters: JSONSchema;
44
+ }
45
+ /**
46
+ * Serialized tool definition (stored in localStorage)
47
+ * Contains executorCode as a string for persistence
48
+ */
49
+ interface SerializedToolDefinition extends ClientToolDefinition {
50
+ /**
51
+ * Stringified executor function body for persistence.
52
+ * Reconstituted at runtime via new Function().
53
+ *
54
+ * FIXME: Add signature verification before execution
55
+ */
56
+ executorCode?: string;
57
+ }
58
+ /**
59
+ * Function that executes the tool client-side
60
+ */
61
+ type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown>;
62
+ /**
63
+ * Request object passed to beforeRequest hook
64
+ */
65
+ interface HustleRequest {
66
+ messages: Array<{
67
+ role: string;
68
+ content: string;
69
+ }>;
70
+ model?: string;
71
+ tools?: ClientToolDefinition[];
72
+ [key: string]: unknown;
73
+ }
74
+ /**
75
+ * Response object passed to afterResponse hook
76
+ */
77
+ interface ProcessedResponse {
78
+ content: string;
79
+ toolCalls?: Array<{
80
+ toolCallId: string;
81
+ toolName: string;
82
+ args: Record<string, unknown>;
83
+ }>;
84
+ [key: string]: unknown;
85
+ }
86
+ /**
87
+ * Error context passed to onError hook
88
+ */
89
+ interface ErrorContext {
90
+ phase: 'request' | 'stream' | 'tool_execution';
91
+ toolName?: string;
92
+ args?: Record<string, unknown>;
93
+ }
94
+ /**
95
+ * Plugin lifecycle hooks
96
+ */
97
+ interface PluginHooks {
98
+ /** Called when plugin is registered */
99
+ onRegister?: () => void | Promise<void>;
100
+ /** Called before each request (can modify request) */
101
+ beforeRequest?: (req: HustleRequest) => HustleRequest | Promise<HustleRequest>;
102
+ /** Called after response is processed */
103
+ afterResponse?: (res: ProcessedResponse) => void | Promise<void>;
104
+ /** Called when an error occurs */
105
+ onError?: (error: Error, context: ErrorContext) => void | Promise<void>;
106
+ }
107
+ /**
108
+ * Serialized plugin hooks (stored in localStorage)
109
+ * Contains hook function bodies as strings for persistence
110
+ *
111
+ * FIXME: Add signature verification before execution
112
+ */
113
+ interface SerializedHooks {
114
+ /** Stringified onRegister function */
115
+ onRegisterCode?: string;
116
+ /** Stringified beforeRequest function */
117
+ beforeRequestCode?: string;
118
+ /** Stringified afterResponse function */
119
+ afterResponseCode?: string;
120
+ /** Stringified onError function */
121
+ onErrorCode?: string;
122
+ }
123
+ /**
124
+ * Plugin definition
125
+ */
126
+ interface HustlePlugin {
127
+ /** Unique plugin identifier */
128
+ name: string;
129
+ /** Semantic version */
130
+ version: string;
131
+ /** Optional description */
132
+ description?: string;
133
+ /** Tool schemas sent to server for AI registration */
134
+ tools?: ClientToolDefinition[];
135
+ /** Local execution functions (keyed by tool name) */
136
+ executors?: Record<string, ToolExecutor>;
137
+ /** Lifecycle hooks */
138
+ hooks?: PluginHooks;
139
+ }
140
+ /**
141
+ * Plugin with enabled state (stored in localStorage)
142
+ * Tools include executorCode for function persistence
143
+ *
144
+ * FIXME: Add `signature?: string` for cryptographic verification
145
+ */
146
+ interface StoredPlugin {
147
+ /** Unique plugin identifier */
148
+ name: string;
149
+ /** Semantic version */
150
+ version: string;
151
+ /** Optional description */
152
+ description?: string;
153
+ /** Tool schemas with serialized executorCode */
154
+ tools?: SerializedToolDefinition[];
155
+ /** Serialized lifecycle hooks */
156
+ hooksCode?: SerializedHooks;
157
+ /** Whether the plugin is enabled */
158
+ enabled: boolean;
159
+ /** Timestamp when plugin was installed */
160
+ installedAt?: string;
161
+ }
162
+ /**
163
+ * Plugin with hydrated executors (ready for use)
164
+ */
165
+ interface HydratedPlugin extends StoredPlugin {
166
+ /** Restored executor functions */
167
+ executors?: Record<string, ToolExecutor>;
168
+ /** Restored hooks */
169
+ hooks?: PluginHooks;
170
+ }
171
+
172
+ export type { ClientToolDefinition as C, ErrorContext as E, HustlePlugin as H, JSONSchema as J, ProcessedResponse as P, StoredPlugin as S, ToolExecutor as T, HydratedPlugin as a, JSONSchemaProperty as b, SerializedToolDefinition as c, HustleRequest as d, PluginHooks as e, SerializedHooks as f };