@vhyxseal/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/dist/components/Button/index.d.ts +22 -0
- package/dist/components/Button/index.d.ts.map +1 -0
- package/dist/components/Button/index.js +18 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Confirmation/index.d.ts +55 -0
- package/dist/components/Confirmation/index.d.ts.map +1 -0
- package/dist/components/Confirmation/index.js +52 -0
- package/dist/components/Confirmation/index.js.map +1 -0
- package/dist/components/Display/index.d.ts +26 -0
- package/dist/components/Display/index.d.ts.map +1 -0
- package/dist/components/Display/index.js +20 -0
- package/dist/components/Display/index.js.map +1 -0
- package/dist/components/Form/index.d.ts +24 -0
- package/dist/components/Form/index.d.ts.map +1 -0
- package/dist/components/Form/index.js +20 -0
- package/dist/components/Form/index.js.map +1 -0
- package/dist/components/Input/index.d.ts +21 -0
- package/dist/components/Input/index.d.ts.map +1 -0
- package/dist/components/Input/index.js +18 -0
- package/dist/components/Input/index.js.map +1 -0
- package/dist/components/Nav/index.d.ts +24 -0
- package/dist/components/Nav/index.d.ts.map +1 -0
- package/dist/components/Nav/index.js +20 -0
- package/dist/components/Nav/index.js.map +1 -0
- package/dist/components/index.d.ts +13 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/shared/useContractRegistration.d.ts +11 -0
- package/dist/components/shared/useContractRegistration.d.ts.map +1 -0
- package/dist/components/shared/useContractRegistration.js +27 -0
- package/dist/components/shared/useContractRegistration.js.map +1 -0
- package/dist/hoc/index.d.ts +2 -0
- package/dist/hoc/index.d.ts.map +1 -0
- package/dist/hoc/index.js +2 -0
- package/dist/hoc/index.js.map +1 -0
- package/dist/hoc/withAgentContract.d.ts +32 -0
- package/dist/hoc/withAgentContract.d.ts.map +1 -0
- package/dist/hoc/withAgentContract.js +57 -0
- package/dist/hoc/withAgentContract.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAgentAction.d.ts +75 -0
- package/dist/hooks/useAgentAction.d.ts.map +1 -0
- package/dist/hooks/useAgentAction.js +103 -0
- package/dist/hooks/useAgentAction.js.map +1 -0
- package/dist/hooks/useCapability.d.ts +35 -0
- package/dist/hooks/useCapability.d.ts.map +1 -0
- package/dist/hooks/useCapability.js +39 -0
- package/dist/hooks/useCapability.js.map +1 -0
- package/dist/hooks/useContract.d.ts +16 -0
- package/dist/hooks/useContract.d.ts.map +1 -0
- package/dist/hooks/useContract.js +19 -0
- package/dist/hooks/useContract.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/SealProvider.d.ts +46 -0
- package/dist/provider/SealProvider.d.ts.map +1 -0
- package/dist/provider/SealProvider.js +103 -0
- package/dist/provider/SealProvider.js.map +1 -0
- package/dist/provider/context.d.ts +41 -0
- package/dist/provider/context.d.ts.map +1 -0
- package/dist/provider/context.js +27 -0
- package/dist/provider/context.js.map +1 -0
- package/dist/provider/index.d.ts +5 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +3 -0
- package/dist/provider/index.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ComponentContract, SafetyLevel } from "@vhyxseal/core";
|
|
2
|
+
/**
|
|
3
|
+
* Lifecycle status of a single agent-initiated action.
|
|
4
|
+
*/
|
|
5
|
+
export type AgentActionStatus = "idle" | "pending" | "confirmed" | "completed" | "failed" | "cancelled";
|
|
6
|
+
/**
|
|
7
|
+
* Immutable record of an agent action attempt, from initiation to terminal state.
|
|
8
|
+
*/
|
|
9
|
+
export interface AgentActionRecord {
|
|
10
|
+
/** Unique identifier for this action instance. */
|
|
11
|
+
actionId: string;
|
|
12
|
+
/** The contract id of the component the agent acted on. */
|
|
13
|
+
contractId: string;
|
|
14
|
+
/** The intent from the component contract. */
|
|
15
|
+
intent: string;
|
|
16
|
+
/** The safety level inherited from the component contract. */
|
|
17
|
+
safetyLevel: SafetyLevel;
|
|
18
|
+
/** Whether the contract required human confirmation. */
|
|
19
|
+
requiresConfirmation: boolean;
|
|
20
|
+
/** True once a human has explicitly confirmed the action. */
|
|
21
|
+
humanConfirmed: boolean;
|
|
22
|
+
/** Current lifecycle status. */
|
|
23
|
+
status: AgentActionStatus;
|
|
24
|
+
/** ISO datetime when the action was initiated. */
|
|
25
|
+
initiatedAt: string;
|
|
26
|
+
/** ISO datetime when the action reached a terminal state. */
|
|
27
|
+
completedAt?: string;
|
|
28
|
+
/** Human-readable error message when status is "failed". */
|
|
29
|
+
errorMessage?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Return value of useAgentAction.
|
|
33
|
+
*/
|
|
34
|
+
export interface UseAgentActionReturn {
|
|
35
|
+
/** All action records, newest first. */
|
|
36
|
+
actions: ReadonlyArray<AgentActionRecord>;
|
|
37
|
+
/** The most recently initiated action, or null when none. */
|
|
38
|
+
currentAction: Readonly<AgentActionRecord> | null;
|
|
39
|
+
/**
|
|
40
|
+
* Initiate a new action from the given contract.
|
|
41
|
+
* @returns The actionId of the newly created record.
|
|
42
|
+
*/
|
|
43
|
+
initiateAction: (contract: Readonly<ComponentContract>) => string;
|
|
44
|
+
/** Mark an action as confirmed by a human. */
|
|
45
|
+
confirmAction: (actionId: string) => void;
|
|
46
|
+
/** Mark an action as successfully completed. */
|
|
47
|
+
completeAction: (actionId: string) => void;
|
|
48
|
+
/** Mark an action as failed with an error message. */
|
|
49
|
+
failAction: (actionId: string, errorMessage: string) => void;
|
|
50
|
+
/** Mark an action as cancelled. */
|
|
51
|
+
cancelAction: (actionId: string) => void;
|
|
52
|
+
/** Clear the entire action history. */
|
|
53
|
+
clearActions: () => void;
|
|
54
|
+
/** True when any action currently has status "pending" or "confirmed". */
|
|
55
|
+
isActionInProgress: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Tracks agent-initiated actions with a full lifecycle from initiation to terminal state.
|
|
59
|
+
* Does not require SealProvider. Can be used anywhere in the component tree.
|
|
60
|
+
*
|
|
61
|
+
* @returns UseAgentActionReturn — the action list, mutation functions, and derived state.
|
|
62
|
+
* @example
|
|
63
|
+
* const { initiateAction, confirmAction, completeAction, isActionInProgress } = useAgentAction();
|
|
64
|
+
*
|
|
65
|
+
* // Agent clicks a button
|
|
66
|
+
* const actionId = initiateAction(contract);
|
|
67
|
+
*
|
|
68
|
+
* // Human confirms
|
|
69
|
+
* confirmAction(actionId);
|
|
70
|
+
*
|
|
71
|
+
* // Action completes
|
|
72
|
+
* completeAction(actionId);
|
|
73
|
+
*/
|
|
74
|
+
export declare function useAgentAction(): UseAgentActionReturn;
|
|
75
|
+
//# sourceMappingURL=useAgentAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgentAction.d.ts","sourceRoot":"","sources":["../../src/hooks/useAgentAction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMrE;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,GACR,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,WAAW,EAAE,WAAW,CAAC;IACzB,wDAAwD;IACxD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,6DAA6D;IAC7D,cAAc,EAAE,OAAO,CAAC;IACxB,gCAAgC;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC1C,6DAA6D;IAC7D,aAAa,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IAClD;;;OAGG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,KAAK,MAAM,CAAC;IAClE,8CAA8C;IAC9C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,gDAAgD;IAChD,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,sDAAsD;IACtD,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,mCAAmC;IACnC,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,uCAAuC;IACvC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,0EAA0E;IAC1E,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AA0CD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,IAAI,oBAAoB,CAmGrD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useState, useRef, useCallback } from "react";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Internal helpers
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Builds an updated AgentActionRecord from an existing record and explicit field
|
|
7
|
+
* overrides. Avoids Partial<T> spread which is unsafe under exactOptionalPropertyTypes.
|
|
8
|
+
*/
|
|
9
|
+
function applyUpdate(existing, status, humanConfirmed, completedAt, errorMessage) {
|
|
10
|
+
const next = {
|
|
11
|
+
actionId: existing.actionId,
|
|
12
|
+
contractId: existing.contractId,
|
|
13
|
+
intent: existing.intent,
|
|
14
|
+
safetyLevel: existing.safetyLevel,
|
|
15
|
+
requiresConfirmation: existing.requiresConfirmation,
|
|
16
|
+
humanConfirmed: humanConfirmed ?? existing.humanConfirmed,
|
|
17
|
+
status: status ?? existing.status,
|
|
18
|
+
initiatedAt: existing.initiatedAt,
|
|
19
|
+
};
|
|
20
|
+
const resolvedCompleted = completedAt ?? existing.completedAt;
|
|
21
|
+
if (resolvedCompleted !== undefined) {
|
|
22
|
+
next.completedAt = resolvedCompleted;
|
|
23
|
+
}
|
|
24
|
+
const resolvedError = errorMessage ?? existing.errorMessage;
|
|
25
|
+
if (resolvedError !== undefined) {
|
|
26
|
+
next.errorMessage = resolvedError;
|
|
27
|
+
}
|
|
28
|
+
return next;
|
|
29
|
+
}
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Hook
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
/**
|
|
34
|
+
* Tracks agent-initiated actions with a full lifecycle from initiation to terminal state.
|
|
35
|
+
* Does not require SealProvider. Can be used anywhere in the component tree.
|
|
36
|
+
*
|
|
37
|
+
* @returns UseAgentActionReturn — the action list, mutation functions, and derived state.
|
|
38
|
+
* @example
|
|
39
|
+
* const { initiateAction, confirmAction, completeAction, isActionInProgress } = useAgentAction();
|
|
40
|
+
*
|
|
41
|
+
* // Agent clicks a button
|
|
42
|
+
* const actionId = initiateAction(contract);
|
|
43
|
+
*
|
|
44
|
+
* // Human confirms
|
|
45
|
+
* confirmAction(actionId);
|
|
46
|
+
*
|
|
47
|
+
* // Action completes
|
|
48
|
+
* completeAction(actionId);
|
|
49
|
+
*/
|
|
50
|
+
export function useAgentAction() {
|
|
51
|
+
const [actions, setActions] = useState([]);
|
|
52
|
+
const counterRef = useRef(0);
|
|
53
|
+
const updateById = useCallback((actionId, status, humanConfirmed, completedAt, errorMessage) => {
|
|
54
|
+
setActions((prev) => prev.map((a) => a.actionId === actionId
|
|
55
|
+
? applyUpdate(a, status, humanConfirmed, completedAt, errorMessage)
|
|
56
|
+
: a));
|
|
57
|
+
}, []);
|
|
58
|
+
const initiateAction = useCallback((contract) => {
|
|
59
|
+
counterRef.current += 1;
|
|
60
|
+
const actionId = `agent-action-${counterRef.current}-${Date.now()}`;
|
|
61
|
+
const record = {
|
|
62
|
+
actionId,
|
|
63
|
+
contractId: contract.id,
|
|
64
|
+
intent: contract.intent,
|
|
65
|
+
safetyLevel: contract.safetyLevel,
|
|
66
|
+
requiresConfirmation: contract.requiresConfirmation,
|
|
67
|
+
humanConfirmed: false,
|
|
68
|
+
status: "pending",
|
|
69
|
+
initiatedAt: new Date().toISOString(),
|
|
70
|
+
};
|
|
71
|
+
setActions((prev) => [record, ...prev]);
|
|
72
|
+
return actionId;
|
|
73
|
+
}, []);
|
|
74
|
+
const confirmAction = useCallback((actionId) => {
|
|
75
|
+
updateById(actionId, "confirmed", true);
|
|
76
|
+
}, [updateById]);
|
|
77
|
+
const completeAction = useCallback((actionId) => {
|
|
78
|
+
updateById(actionId, "completed", undefined, new Date().toISOString());
|
|
79
|
+
}, [updateById]);
|
|
80
|
+
const failAction = useCallback((actionId, errorMessage) => {
|
|
81
|
+
updateById(actionId, "failed", undefined, new Date().toISOString(), errorMessage);
|
|
82
|
+
}, [updateById]);
|
|
83
|
+
const cancelAction = useCallback((actionId) => {
|
|
84
|
+
updateById(actionId, "cancelled", undefined, new Date().toISOString());
|
|
85
|
+
}, [updateById]);
|
|
86
|
+
const clearActions = useCallback(() => {
|
|
87
|
+
setActions([]);
|
|
88
|
+
}, []);
|
|
89
|
+
const currentAction = actions[0] ?? null;
|
|
90
|
+
const isActionInProgress = actions.some((a) => a.status === "pending" || a.status === "confirmed");
|
|
91
|
+
return {
|
|
92
|
+
actions,
|
|
93
|
+
currentAction,
|
|
94
|
+
initiateAction,
|
|
95
|
+
confirmAction,
|
|
96
|
+
completeAction,
|
|
97
|
+
failAction,
|
|
98
|
+
cancelAction,
|
|
99
|
+
clearActions,
|
|
100
|
+
isActionInProgress,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=useAgentAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgentAction.js","sourceRoot":"","sources":["../../src/hooks/useAgentAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAuEtD,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,WAAW,CAClB,QAA2B,EAC3B,MAA0B,EAC1B,cAAwB,EACxB,WAAoB,EACpB,YAAqB;IAErB,MAAM,IAAI,GAAsB;QAC9B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;QACnD,cAAc,EAAE,cAAc,IAAI,QAAQ,CAAC,cAAc;QACzD,MAAM,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM;QACjC,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;IACF,MAAM,iBAAiB,GAAG,WAAW,IAAI,QAAQ,CAAC,WAAW,CAAC;IAC9D,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC;IACvC,CAAC;IACD,MAAM,aAAa,GAAG,YAAY,IAAI,QAAQ,CAAC,YAAY,CAAC;IAC5D,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,IAAI,CAA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,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,WAAW,CAC1D,CAAC;IAEF,OAAO;QACL,OAAO;QACP,aAAa;QACb,cAAc;QACd,aAAa;QACb,cAAc;QACd,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useSealContext } from "../provider/context.js";
|
|
2
|
+
import type { ComponentContract } from "@vhyxseal/core";
|
|
3
|
+
/**
|
|
4
|
+
* Structured view of all contracts registered in the current SealProvider scope.
|
|
5
|
+
* Useful for DevTools panels and agent-facing components.
|
|
6
|
+
*/
|
|
7
|
+
export interface CapabilityMap {
|
|
8
|
+
/** All contracts keyed by component id. */
|
|
9
|
+
contracts: ReadonlyMap<string, Readonly<ComponentContract>>;
|
|
10
|
+
/** Total number of registered contracts. */
|
|
11
|
+
contractCount: number;
|
|
12
|
+
/** Contracts grouped by ComponentType (action, input, navigation, display, confirmation). */
|
|
13
|
+
byType: Readonly<Record<string, ReadonlyArray<Readonly<ComponentContract>>>>;
|
|
14
|
+
/** Contracts grouped by SafetyLevel (low, medium, high, critical, sensitive). */
|
|
15
|
+
bySafetyLevel: Readonly<Record<string, ReadonlyArray<Readonly<ComponentContract>>>>;
|
|
16
|
+
/** True when at least one contract is registered. */
|
|
17
|
+
hasContracts: boolean;
|
|
18
|
+
/** The most recently generated manifest, or null. */
|
|
19
|
+
manifest: ReturnType<typeof useSealContext>["manifest"];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns a structured capability map of all contracts in the current SealProvider scope.
|
|
23
|
+
* Useful for DevTools panels and agent-facing components that need a higher-level view.
|
|
24
|
+
* Must be used within a SealProvider.
|
|
25
|
+
*
|
|
26
|
+
* @returns CapabilityMap derived from all registered contracts.
|
|
27
|
+
* @throws {Error} when used outside a SealProvider.
|
|
28
|
+
* @example
|
|
29
|
+
* const { contractCount, byType, hasContracts } = useCapability();
|
|
30
|
+
* if (hasContracts) {
|
|
31
|
+
* const actionContracts = byType['action'] ?? [];
|
|
32
|
+
* }
|
|
33
|
+
*/
|
|
34
|
+
export declare function useCapability(): CapabilityMap;
|
|
35
|
+
//# sourceMappingURL=useCapability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCapability.d.ts","sourceRoot":"","sources":["../../src/hooks/useCapability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC5D,4CAA4C;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,6FAA6F;IAC7F,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,iFAAiF;IACjF,aAAa,EAAE,QAAQ,CACrB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAC3D,CAAC;IACF,qDAAqD;IACrD,YAAY,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,QAAQ,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,UAAU,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,IAAI,aAAa,CAyB7C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useSealContext } from "../provider/context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a structured capability map of all contracts in the current SealProvider scope.
|
|
4
|
+
* Useful for DevTools panels and agent-facing components that need a higher-level view.
|
|
5
|
+
* Must be used within a SealProvider.
|
|
6
|
+
*
|
|
7
|
+
* @returns CapabilityMap derived from all registered contracts.
|
|
8
|
+
* @throws {Error} when used outside a SealProvider.
|
|
9
|
+
* @example
|
|
10
|
+
* const { contractCount, byType, hasContracts } = useCapability();
|
|
11
|
+
* if (hasContracts) {
|
|
12
|
+
* const actionContracts = byType['action'] ?? [];
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export function useCapability() {
|
|
16
|
+
const ctx = useSealContext();
|
|
17
|
+
const { contracts } = ctx;
|
|
18
|
+
const byType = {};
|
|
19
|
+
const bySafetyLevel = {};
|
|
20
|
+
for (const contract of contracts.values()) {
|
|
21
|
+
const type = contract.type;
|
|
22
|
+
if (!byType[type])
|
|
23
|
+
byType[type] = [];
|
|
24
|
+
byType[type].push(contract);
|
|
25
|
+
const level = contract.safetyLevel;
|
|
26
|
+
if (!bySafetyLevel[level])
|
|
27
|
+
bySafetyLevel[level] = [];
|
|
28
|
+
bySafetyLevel[level].push(contract);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
contracts,
|
|
32
|
+
contractCount: contracts.size,
|
|
33
|
+
byType,
|
|
34
|
+
bySafetyLevel,
|
|
35
|
+
hasContracts: contracts.size > 0,
|
|
36
|
+
manifest: ctx.manifest,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=useCapability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCapability.js","sourceRoot":"","sources":["../../src/hooks/useCapability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAwBxD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;IAC7B,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;IAE1B,MAAM,MAAM,GAAkD,EAAE,CAAC;IACjE,MAAM,aAAa,GAAkD,EAAE,CAAC;IAExE,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE7B,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;YAAE,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACrD,aAAa,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED,OAAO;QACL,SAAS;QACT,aAAa,EAAE,SAAS,CAAC,IAAI;QAC7B,MAAM;QACN,aAAa;QACb,YAAY,EAAE,SAAS,CAAC,IAAI,GAAG,CAAC;QAChC,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentContract } from "@vhyxseal/core";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the contract registered under the given id, or undefined if not found.
|
|
4
|
+
* Must be used within a SealProvider.
|
|
5
|
+
*
|
|
6
|
+
* @param id - The contract id to look up.
|
|
7
|
+
* @returns The contract if registered, undefined otherwise.
|
|
8
|
+
* @throws {Error} when used outside a SealProvider.
|
|
9
|
+
* @example
|
|
10
|
+
* const contract = useContract('checkout-submit-btn');
|
|
11
|
+
* if (contract) {
|
|
12
|
+
* console.log(contract.safetyLevel);
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export declare function useContract(id: string): Readonly<ComponentContract> | undefined;
|
|
16
|
+
//# sourceMappingURL=useContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContract.d.ts","sourceRoot":"","sources":["../../src/hooks/useContract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAG/E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useSealContext } from "../provider/context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the contract registered under the given id, or undefined if not found.
|
|
4
|
+
* Must be used within a SealProvider.
|
|
5
|
+
*
|
|
6
|
+
* @param id - The contract id to look up.
|
|
7
|
+
* @returns The contract if registered, undefined otherwise.
|
|
8
|
+
* @throws {Error} when used outside a SealProvider.
|
|
9
|
+
* @example
|
|
10
|
+
* const contract = useContract('checkout-submit-btn');
|
|
11
|
+
* if (contract) {
|
|
12
|
+
* console.log(contract.safetyLevel);
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export function useContract(id) {
|
|
16
|
+
const ctx = useSealContext();
|
|
17
|
+
return ctx.contracts.get(id);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=useContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContract.js","sourceRoot":"","sources":["../../src/hooks/useContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;IAC7B,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SealProvider — root React context provider for VhyxSeal.
|
|
3
|
+
*
|
|
4
|
+
* Collects component contracts from the subtree, generates a manifest
|
|
5
|
+
* whenever contracts change, and exposes both via SealContext.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactNode } from "react";
|
|
8
|
+
import { type VhyxSealManifest, type ManifestConfig } from "@vhyxseal/core";
|
|
9
|
+
/**
|
|
10
|
+
* Props for the SealProvider component.
|
|
11
|
+
*/
|
|
12
|
+
export interface SealProviderProps {
|
|
13
|
+
/** Child components — the component tree that can register contracts. */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/** Configuration forwarded to generateManifest on each contract change. */
|
|
16
|
+
config: ManifestConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Enable development mode features: verbose console logging, DevTools.
|
|
19
|
+
* Defaults to `process.env.NODE_ENV !== "production"` when process is available,
|
|
20
|
+
* or `true` in browser environments where process is not defined.
|
|
21
|
+
*/
|
|
22
|
+
dev?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Called each time a new manifest is successfully generated.
|
|
25
|
+
* Useful for testing, debugging, or forwarding the manifest to a server.
|
|
26
|
+
*/
|
|
27
|
+
onManifestGenerated?: (manifest: Readonly<VhyxSealManifest>) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Root context provider for the VhyxSeal React adapter.
|
|
31
|
+
*
|
|
32
|
+
* Place this at the top of the component tree (or around any subtree where
|
|
33
|
+
* VhyxSeal components will be used). Child components call `registerContract`
|
|
34
|
+
* via the context to contribute their contracts to the manifest.
|
|
35
|
+
*
|
|
36
|
+
* The manifest is regenerated automatically whenever the set of registered
|
|
37
|
+
* contracts changes. Generation errors are caught internally — they never
|
|
38
|
+
* propagate to the render tree.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* <SealProvider config={{ domain: "example.com", domainVerified: false, verificationToken: "" }}>
|
|
42
|
+
* <App />
|
|
43
|
+
* </SealProvider>
|
|
44
|
+
*/
|
|
45
|
+
export declare function SealProvider({ children, config, dev, onManifestGenerated, }: SealProviderProps): ReactNode;
|
|
46
|
+
//# sourceMappingURL=SealProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SealProvider.d.ts","sourceRoot":"","sources":["../../src/provider/SealProvider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAOxB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,QAAQ,EAAE,SAAS,CAAC;IACpB,2EAA2E;IAC3E,MAAM,EAAE,cAAc,CAAC;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CACtE;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,GAAG,EACH,mBAAmB,GACpB,EAAE,iBAAiB,GAAG,SAAS,CA4F/B"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* SealProvider — root React context provider for VhyxSeal.
|
|
4
|
+
*
|
|
5
|
+
* Collects component contracts from the subtree, generates a manifest
|
|
6
|
+
* whenever contracts change, and exposes both via SealContext.
|
|
7
|
+
*/
|
|
8
|
+
import { useState, useCallback, useMemo, useEffect, } from "react";
|
|
9
|
+
import { generateManifest, } from "@vhyxseal/core";
|
|
10
|
+
import { SealContext } from "./context.js";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Component
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/**
|
|
15
|
+
* Root context provider for the VhyxSeal React adapter.
|
|
16
|
+
*
|
|
17
|
+
* Place this at the top of the component tree (or around any subtree where
|
|
18
|
+
* VhyxSeal components will be used). Child components call `registerContract`
|
|
19
|
+
* via the context to contribute their contracts to the manifest.
|
|
20
|
+
*
|
|
21
|
+
* The manifest is regenerated automatically whenever the set of registered
|
|
22
|
+
* contracts changes. Generation errors are caught internally — they never
|
|
23
|
+
* propagate to the render tree.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* <SealProvider config={{ domain: "example.com", domainVerified: false, verificationToken: "" }}>
|
|
27
|
+
* <App />
|
|
28
|
+
* </SealProvider>
|
|
29
|
+
*/
|
|
30
|
+
export function SealProvider({ children, config, dev, onManifestGenerated, }) {
|
|
31
|
+
// Determine development mode once. Process may not exist in all environments.
|
|
32
|
+
const isDev = useMemo(() => {
|
|
33
|
+
if (dev !== undefined) {
|
|
34
|
+
return dev;
|
|
35
|
+
}
|
|
36
|
+
if (typeof process !== "undefined" && process.env !== undefined) {
|
|
37
|
+
return process.env["NODE_ENV"] !== "production";
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}, [dev]);
|
|
41
|
+
// The contracts map — keyed by component id.
|
|
42
|
+
const [contracts, setContracts] = useState(new Map());
|
|
43
|
+
/**
|
|
44
|
+
* Adds or replaces a contract in the registry.
|
|
45
|
+
* Warns in dev mode when the same id is re-registered with a different fingerprint.
|
|
46
|
+
*/
|
|
47
|
+
const registerContract = useCallback((contract) => {
|
|
48
|
+
setContracts((prev) => {
|
|
49
|
+
const existing = prev.get(contract.id);
|
|
50
|
+
if (isDev &&
|
|
51
|
+
existing !== undefined &&
|
|
52
|
+
existing.fingerprint !== contract.fingerprint) {
|
|
53
|
+
console.warn(`[VhyxSeal] Contract "${contract.id}" was re-registered with a different fingerprint. ` +
|
|
54
|
+
"This may indicate the contract definition changed unexpectedly.");
|
|
55
|
+
}
|
|
56
|
+
const next = new Map(prev);
|
|
57
|
+
next.set(contract.id, contract);
|
|
58
|
+
return next;
|
|
59
|
+
});
|
|
60
|
+
}, [isDev]);
|
|
61
|
+
/**
|
|
62
|
+
* Removes a contract from the registry by id. Silent if not found.
|
|
63
|
+
*/
|
|
64
|
+
const unregisterContract = useCallback((id) => {
|
|
65
|
+
setContracts((prev) => {
|
|
66
|
+
if (!prev.has(id)) {
|
|
67
|
+
return prev;
|
|
68
|
+
}
|
|
69
|
+
const next = new Map(prev);
|
|
70
|
+
next.delete(id);
|
|
71
|
+
return next;
|
|
72
|
+
});
|
|
73
|
+
}, []);
|
|
74
|
+
// Generate manifest whenever contracts or config changes.
|
|
75
|
+
const manifest = useMemo(() => {
|
|
76
|
+
try {
|
|
77
|
+
const contractsArray = Array.from(contracts.values());
|
|
78
|
+
return generateManifest(contractsArray, config);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (isDev) {
|
|
82
|
+
console.error("[VhyxSeal] Manifest generation failed:", err);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}, [contracts, config, isDev]);
|
|
87
|
+
// Notify the caller when a new manifest is produced.
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (manifest !== null && onManifestGenerated !== undefined) {
|
|
90
|
+
onManifestGenerated(manifest);
|
|
91
|
+
}
|
|
92
|
+
}, [manifest, onManifestGenerated]);
|
|
93
|
+
// Memoize the context value to avoid unnecessary re-renders of consumers.
|
|
94
|
+
const contextValue = useMemo(() => ({
|
|
95
|
+
contracts,
|
|
96
|
+
registerContract,
|
|
97
|
+
unregisterContract,
|
|
98
|
+
manifest,
|
|
99
|
+
isDev,
|
|
100
|
+
}), [contracts, registerContract, unregisterContract, manifest, isDev]);
|
|
101
|
+
return (_jsx(SealContext.Provider, { value: contextValue, children: children }));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=SealProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SealProvider.js","sourceRoot":"","sources":["../../src/provider/SealProvider.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,OAAO,EACP,SAAS,GAEV,MAAM,OAAO,CAAC;AACf,OAAO,EACL,gBAAgB,GAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAyB,MAAM,cAAc,CAAC;AA2BlE,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,GAAG,EACH,mBAAmB,GACD;IAClB,8EAA8E;IAC9E,MAAM,KAAK,GAAG,OAAO,CAAU,GAAG,EAAE;QAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAChE,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY,CAAC;QAClD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,6CAA6C;IAC7C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ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,MAAM,EAAE,CAAC,CAAC;YACtD,OAAO,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;YAC/D,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAE/B,qDAAqD;IACrD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,KAAK,IAAI,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC3D,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEpC,0EAA0E;IAC1E,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,gBAAgB;QAChB,kBAAkB;QAClB,QAAQ;QACR,KAAK;KACN,CAAC,EACF,CAAC,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,CAAC,CACnE,CAAC;IAEF,OAAO,CACL,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAAG,QAAQ,GAAwB,CAC7E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SealContext — React context for the VhyxSeal contract layer.
|
|
3
|
+
*
|
|
4
|
+
* Kept in a separate file from the provider so hooks can import the context
|
|
5
|
+
* without pulling in the provider JSX.
|
|
6
|
+
*/
|
|
7
|
+
import type { ComponentContract, VhyxSealManifest } from "@vhyxseal/core";
|
|
8
|
+
/**
|
|
9
|
+
* The value shape exposed by SealContext to all consumers.
|
|
10
|
+
*/
|
|
11
|
+
export interface SealContextValue {
|
|
12
|
+
/** All contracts registered in this provider scope, keyed by component id. */
|
|
13
|
+
contracts: ReadonlyMap<string, Readonly<ComponentContract>>;
|
|
14
|
+
/**
|
|
15
|
+
* Register a contract from a child component.
|
|
16
|
+
* Called during render or in an effect — replaces any existing contract with the same id.
|
|
17
|
+
*/
|
|
18
|
+
registerContract: (contract: Readonly<ComponentContract>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Unregister a contract by id.
|
|
21
|
+
* Called when a child component unmounts. Silent if the id is not found.
|
|
22
|
+
*/
|
|
23
|
+
unregisterContract: (id: string) => void;
|
|
24
|
+
/** The most recently generated manifest, or null if generation has not yet occurred. */
|
|
25
|
+
manifest: Readonly<VhyxSealManifest> | null;
|
|
26
|
+
/** True when the provider is in development mode — enables verbose logging and DevTools. */
|
|
27
|
+
isDev: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The React context for VhyxSeal. Default value is null — must be provided by SealProvider. */
|
|
30
|
+
export declare const SealContext: import("react").Context<SealContextValue | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the SealContext value. Throws when called outside a SealProvider.
|
|
33
|
+
*
|
|
34
|
+
* Throws a native Error (not VhyxSealError) because this is a developer
|
|
35
|
+
* mistake caught at development time, not a runtime contract error that
|
|
36
|
+
* should be handled gracefully.
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} when used outside a SealProvider.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useSealContext(): SealContextValue;
|
|
41
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/provider/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC5D;;;OAGG;IACH,gBAAgB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAClE;;;OAGG;IACH,kBAAkB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,wFAAwF;IACxF,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;IAC5C,4FAA4F;IAC5F,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,gGAAgG;AAChG,eAAO,MAAM,WAAW,kDAA+C,CAAC;AAExE;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CASjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SealContext — React context for the VhyxSeal contract layer.
|
|
3
|
+
*
|
|
4
|
+
* Kept in a separate file from the provider so hooks can import the context
|
|
5
|
+
* without pulling in the provider JSX.
|
|
6
|
+
*/
|
|
7
|
+
import { createContext, useContext } from "react";
|
|
8
|
+
/** The React context for VhyxSeal. Default value is null — must be provided by SealProvider. */
|
|
9
|
+
export const SealContext = createContext(null);
|
|
10
|
+
/**
|
|
11
|
+
* Returns the SealContext value. Throws when called outside a SealProvider.
|
|
12
|
+
*
|
|
13
|
+
* Throws a native Error (not VhyxSealError) because this is a developer
|
|
14
|
+
* mistake caught at development time, not a runtime contract error that
|
|
15
|
+
* should be handled gracefully.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} when used outside a SealProvider.
|
|
18
|
+
*/
|
|
19
|
+
export function useSealContext() {
|
|
20
|
+
const ctx = useContext(SealContext);
|
|
21
|
+
if (ctx === null) {
|
|
22
|
+
throw new Error("[VhyxSeal] useSealContext must be used within a SealProvider. " +
|
|
23
|
+
"Wrap your application or component tree with <SealProvider>.");
|
|
24
|
+
}
|
|
25
|
+
return ctx;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/provider/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAyBlD,gGAAgG;AAChG,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,gEAAgE;YAC9D,8DAA8D,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vhyxseal/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react": ">=18.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@testing-library/dom": "^10.0.0",
|
|
19
|
+
"@testing-library/react": "^16.0.0",
|
|
20
|
+
"@types/react": "^19.0.0",
|
|
21
|
+
"@types/react-dom": "^19.0.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
23
|
+
"happy-dom": "^20.9.0",
|
|
24
|
+
"jsdom": "^24.0.0",
|
|
25
|
+
"react": "^19.0.0",
|
|
26
|
+
"react-dom": "^19.0.0",
|
|
27
|
+
"typescript": "^5.4.0",
|
|
28
|
+
"vitest": "^1.6.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@vhyxseal/core": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"typecheck": "tsc --project tsconfig.test.json"
|
|
37
|
+
}
|
|
38
|
+
}
|